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

Api token authc/z implementation with Cache #4992

Open
wants to merge 11 commits into
base: feature/api-tokens
Choose a base branch
from

Conversation

derek-ho
Copy link
Collaborator

@derek-ho derek-ho commented Dec 24, 2024

Description

This PR implements authc/z for api tokens. For authc it is based on token validity for as well as presence in a cache, which listens to index and delete operations on the api token index. For Authz, it onboards onto action privileges class, where instead of returning not authorized for cluster and index privileges, requests go through a final api token check, where if the user is an api token, it will evaluate whether the permissions in the cache are sufficient to execute the request.

Issues Resolved

[List any issues this PR will resolve]

Is this a backport? If so, please add backport PR # and/or commits #, and remove backport-failed label from the original PR.

Do these changes introduce new permission(s) to be displayed in the static dropdown on the front-end? If so, please open a draft PR in the security dashboards plugin and link the draft PR here

Testing

[Please provide details of testing done: unit testing, integration testing and manual testing]

Check List

  • New functionality includes testing
  • New functionality has been documented
  • New Roles/Permissions have a corresponding security dashboards plugin PR
  • API changes companion pull request created
  • 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.

@derek-ho derek-ho changed the title Naive cluster permission authz and authc based on token validity Naive authc+z api token implementation Dec 26, 2024
Copy link

codecov bot commented Dec 26, 2024

Codecov Report

Attention: Patch coverage is 62.50000% with 84 lines in your changes missing coverage. Please review.

Project coverage is 71.38%. Comparing base (0edba23) to head (6418226).
Report is 10 commits behind head on feature/api-tokens.

Files with missing lines Patch % Lines
...pensearch/security/http/ApiTokenAuthenticator.java 64.63% 20 Missing and 9 partials ⚠️
...y/action/apitokens/ApiTokenIndexListenerCache.java 25.00% 21 Missing ⚠️
...ensearch/security/privileges/ActionPrivileges.java 80.76% 5 Missing and 10 partials ⚠️
...earch/security/auditlog/impl/AbstractAuditLog.java 40.00% 3 Missing and 3 partials ⚠️
.../opensearch/security/OpenSearchSecurityPlugin.java 0.00% 4 Missing and 1 partial ⚠️
...nsearch/security/action/apitokens/Permissions.java 60.00% 4 Missing ⚠️
...ch/security/securityconf/DynamicConfigModelV7.java 20.00% 3 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@                  Coverage Diff                   @@
##           feature/api-tokens    #4992      +/-   ##
======================================================
- Coverage               71.46%   71.38%   -0.09%     
======================================================
  Files                     334      343       +9     
  Lines                   22552    23131     +579     
  Branches                 3590     3669      +79     
======================================================
+ Hits                    16117    16511     +394     
- Misses                   4642     4795     +153     
- Partials                 1793     1825      +32     
Files with missing lines Coverage Δ
.../security/action/apitokens/ApiTokenRepository.java 100.00% <100.00%> (ø)
...g/opensearch/security/authtoken/jwt/JwtVendor.java 88.00% <ø> (-1.10%) ⬇️
...search/security/identity/SecurityTokenManager.java 82.75% <100.00%> (-6.61%) ⬇️
...curity/privileges/PrivilegesEvaluationContext.java 97.43% <100.00%> (+0.13%) ⬆️
...g/opensearch/security/ssl/util/ExceptionUtils.java 45.83% <100.00%> (+2.35%) ⬆️
...a/org/opensearch/security/util/AuthTokenUtils.java 66.66% <100.00%> (+4.16%) ⬆️
...nsearch/security/action/apitokens/Permissions.java 60.00% <60.00%> (ø)
...ch/security/securityconf/DynamicConfigModelV7.java 73.22% <20.00%> (-1.07%) ⬇️
.../opensearch/security/OpenSearchSecurityPlugin.java 83.01% <0.00%> (-0.55%) ⬇️
...earch/security/auditlog/impl/AbstractAuditLog.java 76.88% <40.00%> (+0.15%) ⬆️
... and 3 more

... and 6 files with indirect coverage changes

originalSource = (new String(BaseEncoding.base64().decode((String) base64), StandardCharsets.UTF_8));
} else {
originalSource = XContentHelper.convertToJson(originalResult.internalSourceRef(), false, XContentType.JSON);
if (originalSource == null) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changes in this file are to correct a mis-merge that happened in prior PRs to this feature branch.

@derek-ho derek-ho marked this pull request as ready for review December 31, 2024 21:57
@derek-ho derek-ho changed the title Naive authc+z api token implementation Api token authc/z implementation with Cache Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant