Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Extensions] Generate auth tokens for service accounts #2716

Merged
merged 48 commits into from
May 3, 2023

Conversation

stephen-crawford
Copy link
Contributor

Description

This is a PR to introduce the functionality for generating an auth token for an extension. The auth token consists of a an encoded basic auth token created from a randomly generated password. The token is then passed back to the client so that changes can be made in core in order to later perform authentication and authorization using the token.

Issues Resolved

This issue addresses This PR covers issue #2611 and issue #2668.

Testing

New tests are added to the UserApiTest file.

Check List

  • New functionality includes testing
  • New functionality has been documented
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Copy link
Member

@DarshitChanpura DarshitChanpura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request 1 change. Looks good to me otherwise.

if (Objects.requireNonNull(securityJsonNode.get("isEnabled").asString()).equalsIgnoreCase("false")) { // If the service account is not active
throw new UserServiceException(AUTH_TOKEN_GENERATION_MESSAGE);
if (Optional.of(securityJsonNode.get("isEnabled").asString().equalsIgnoreCase("false")).orElseThrow(() -> {throw new UserServiceException(AUTH_TOKEN_GENERATION_MESSAGE);})) {
throw new UserServiceException(AUTH_TOKEN_GENERATION_MESSAGE); // If the service account is not active
Copy link
Member

@DarshitChanpura DarshitChanpura May 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

orElseThrow will not be utilized here as the value will either be a boolean or it will throw an NPE stating return value of isEnabled is null. In order to utilize orElseThrow to catch a missing isEnabled or isService property in SecurityJsonNode, you can make following changes:

        UserServiceException e = new UserServiceException(AUTH_TOKEN_GENERATION_MESSAGE);
        boolean isService = readBooleanFromJsonNode(securityJsonNode, "isService", e);
        boolean isEnabled = readBooleanFromJsonNode(securityJsonNode, "isEnabled", e);
        
        if(!isService || !isEnabled) {
            throw e;
        }

        private boolean readBooleanFromJsonNode(SecurityJsonNode node, String key, Exception e) {
	    return Boolean.parseBoolean(Optional.ofNullable(node.get(key)).orElseThrow(() -> e).asText());
	}

Signed-off-by: Stephen Crawford <[email protected]>
DarshitChanpura
DarshitChanpura previously approved these changes May 2, 2023
Copy link
Member

@DarshitChanpura DarshitChanpura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @scrawfor99 !

Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
DarshitChanpura
DarshitChanpura previously approved these changes May 2, 2023
peternied
peternied previously approved these changes May 2, 2023
@stephen-crawford stephen-crawford dismissed stale reviews from peternied and DarshitChanpura via e5d92df May 3, 2023 14:04
@stephen-crawford stephen-crawford added the backport 2.x backport to 2.x branch label May 3, 2023
@peternied peternied merged commit 1201335 into opensearch-project:main May 3, 2023
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.x 2.x
# Navigate to the new working tree
cd .worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-2716-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 1201335bd1c95fc2bb7e9b2210ffe5e029457d25
# Push it to GitHub
git push --set-upstream origin backport/backport-2716-to-2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-2716-to-2.x.

stephen-crawford added a commit to stephen-crawford/security that referenced this pull request May 3, 2023
…oject#2716)

* Generate auth tokens for service accounts

Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
stephen-crawford added a commit to stephen-crawford/security that referenced this pull request May 4, 2023
…oject#2716)

* Generate auth tokens for service accounts

Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
stephen-crawford added a commit to stephen-crawford/security that referenced this pull request May 16, 2023
…oject#2716)

* Generate auth tokens for service accounts

Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
stephen-crawford added a commit that referenced this pull request May 17, 2023
…s, and multi tenancy changes (#2737)

* [Extensions] Generate auth tokens for service accounts (#2716)

* Generate auth tokens for service accounts

Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>

* Security User Refactor (#2594)

---------

Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>

* Backport service account changes

Signed-off-by: Stephen Crawford <[email protected]>

* Update test

Signed-off-by: Stephen Crawford <[email protected]>

* Optimize imports

Signed-off-by: Stephen Crawford <[email protected]>

* Spotless

Signed-off-by: Stephen Crawford <[email protected]>

* fix plugin

Signed-off-by: Stephen Crawford <[email protected]>

* fix whitespace

Signed-off-by: Stephen Crawford <[email protected]>

* Fix multitency config update (#2758)

Moved multi-tenancy to REST API implementation

Signed-off-by: Andrey Pleskach <[email protected]>

* Remove SSLCertsAction

Signed-off-by: Stephen Crawford <[email protected]>

* Fix dependency

Signed-off-by: Stephen Crawford <[email protected]>

* fix tenancy tests

Signed-off-by: Stephen Crawford <[email protected]>

---------

Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Andrey Pleskach <[email protected]>
Co-authored-by: Andrey Pleskach <[email protected]>
opensearch-trigger-bot bot pushed a commit that referenced this pull request May 17, 2023
…s, and multi tenancy changes (#2737)

* [Extensions] Generate auth tokens for service accounts (#2716)

* Generate auth tokens for service accounts

Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>

* Security User Refactor (#2594)

---------

Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>

* Backport service account changes

Signed-off-by: Stephen Crawford <[email protected]>

* Update test

Signed-off-by: Stephen Crawford <[email protected]>

* Optimize imports

Signed-off-by: Stephen Crawford <[email protected]>

* Spotless

Signed-off-by: Stephen Crawford <[email protected]>

* fix plugin

Signed-off-by: Stephen Crawford <[email protected]>

* fix whitespace

Signed-off-by: Stephen Crawford <[email protected]>

* Fix multitency config update (#2758)

Moved multi-tenancy to REST API implementation

Signed-off-by: Andrey Pleskach <[email protected]>

* Remove SSLCertsAction

Signed-off-by: Stephen Crawford <[email protected]>

* Fix dependency

Signed-off-by: Stephen Crawford <[email protected]>

* fix tenancy tests

Signed-off-by: Stephen Crawford <[email protected]>

---------

Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Andrey Pleskach <[email protected]>
Co-authored-by: Andrey Pleskach <[email protected]>
(cherry picked from commit fa33fc5)
DarshitChanpura pushed a commit that referenced this pull request May 17, 2023
…s, and multi tenancy changes (#2737) (#2777)

* [Extensions] Generate auth tokens for service accounts (#2716)

* Generate auth tokens for service accounts

Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>

* Security User Refactor (#2594)

---------

Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>

* Backport service account changes

Signed-off-by: Stephen Crawford <[email protected]>

* Update test

Signed-off-by: Stephen Crawford <[email protected]>

* Optimize imports

Signed-off-by: Stephen Crawford <[email protected]>

* Spotless

Signed-off-by: Stephen Crawford <[email protected]>

* fix plugin

Signed-off-by: Stephen Crawford <[email protected]>

* fix whitespace

Signed-off-by: Stephen Crawford <[email protected]>

* Fix multitency config update (#2758)

Moved multi-tenancy to REST API implementation

Signed-off-by: Andrey Pleskach <[email protected]>

* Remove SSLCertsAction

Signed-off-by: Stephen Crawford <[email protected]>

* Fix dependency

Signed-off-by: Stephen Crawford <[email protected]>

* fix tenancy tests

Signed-off-by: Stephen Crawford <[email protected]>

---------

Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Andrey Pleskach <[email protected]>
Co-authored-by: Andrey Pleskach <[email protected]>
(cherry picked from commit fa33fc5)

Co-authored-by: Stephen Crawford <[email protected]>
sebastianmichalski pushed a commit to sebastianmichalski/security that referenced this pull request May 19, 2023
…oject#2716)

* Generate auth tokens for service accounts

Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
MaciejMierzwa pushed a commit to MaciejMierzwa/security that referenced this pull request Jun 13, 2023
…oject#2716)

* Generate auth tokens for service accounts

Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Maciej Mierzwa <[email protected]>
MaciejMierzwa pushed a commit to MaciejMierzwa/security that referenced this pull request Jun 13, 2023
…oject#2716)

* Generate auth tokens for service accounts

Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Maciej Mierzwa <[email protected]>
samuelcostae pushed a commit to samuelcostae/security that referenced this pull request Jun 19, 2023
…oject#2716)

* Generate auth tokens for service accounts

Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Sam <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x backport to 2.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants