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

Fix cluster default initialization #1 #4002

Merged

Conversation

willyborankin
Copy link
Collaborator

@willyborankin willyborankin commented Jan 29, 2024

Description

Change the way how the security plugin initialize its configuration.
The current solution uses poll to upload the default security configuration from each node in the cluster. As result it could lead to the races during initialization of the security index.

To solve the problem with possible races the new solution uses cluster state and initializes the default configuration only on the management node and after that sends updated cluster state on all other nodes to load the configuration from the index.

Initialization using cluster state makes things much more simpler and security admin shell script can be removed in the future.

the cluster state for the security plugin is this:

"security": {
    "created": "2024-02-27T15:44:44.194028751Z",
    "configuration": {
      "actiongroups": {
        "hash": "219b41179866fc2419b736aff874a23f",
        "last_modified": null
      },
      "allowlist": {
        "hash": "522ce41bf5755eeb591d0161844830c0",
        "last_modified": null
      },
      "config": {
        "hash": "d97d664526b42ffa583dbb492742d3cc",
        "last_modified": null
      },
      "internalusers": {
        "hash": "f15fbfe131e0beb466313906d207f00b",
        "last_modified": null
      },
      "nodesdn": {
        "hash": "38e29064f142bfdf8632bc1a66cf8d00",
        "last_modified": null
      },
      "roles": {
        "hash": "db58ba06f214bfb53eee783378f5500c",
        "last_modified": null
      },
      "rolesmapping": {
        "hash": "f2b1cbdf73fa861f1321983cb0241964",
        "last_modified": null
      },
      "tenants": {
        "hash": "7942de6dc0f3bade63d8fc4b49d727d2",
        "last_modified": null
      },
      "whitelist": {
        "hash": "b73aadf21bca6a0de199121d982da460",
        "last_modified": null
      }
    }
  }

Next steps as a separate PRs:

Issues Resolved

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.

@willyborankin willyborankin force-pushed the init-index-on-managed-node branch 3 times, most recently from 627b33a to eb90543 Compare January 29, 2024 22:19
@willyborankin
Copy link
Collaborator Author

willyborankin commented Jan 29, 2024

Hi @cliu123, @cwperks, @DarshitChanpura, @davidlago, @peternied , @RyanL1997, @scrawfor99 and @reta,
Lets discuss the new way of the sec plugin configuration initialization. There are test failures I think I know where is the problem. But I think it makes sense to start discussions. Thank you.

@willyborankin willyborankin force-pushed the init-index-on-managed-node branch 2 times, most recently from 5fc0627 to 26e1adf Compare January 30, 2024 10:05
Copy link

codecov bot commented Jan 30, 2024

Codecov Report

Attention: Patch coverage is 87.62542% with 37 lines in your changes are missing coverage. Please review.

Project coverage is 66.23%. Comparing base (a731e62) to head (27791b4).
Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4002      +/-   ##
==========================================
+ Coverage   66.04%   66.23%   +0.18%     
==========================================
  Files         300      302       +2     
  Lines       21554    21698     +144     
  Branches     3488     3501      +13     
==========================================
+ Hits        14235    14371     +136     
- Misses       5571     5574       +3     
- Partials     1748     1753       +5     
Files Coverage Δ
...g/opensearch/security/support/ConfigConstants.java 95.23% <ø> (ø)
.../org/opensearch/security/support/ConfigHelper.java 88.46% <ø> (ø)
.../opensearch/security/OpenSearchSecurityPlugin.java 84.61% <91.66%> (-0.14%) ⬇️
...ecurityconf/impl/SecurityDynamicConfiguration.java 79.52% <0.00%> (+0.95%) ⬆️
.../opensearch/security/support/YamlConfigReader.java 96.66% <96.66%> (ø)
...nsearch/security/support/SecurityIndexHandler.java 96.22% <96.22%> (ø)
.../org/opensearch/security/state/SecurityConfig.java 78.94% <78.94%> (ø)
...rg/opensearch/security/state/SecurityMetadata.java 78.37% <78.37%> (ø)
...ecurity/configuration/ConfigurationRepository.java 72.51% <81.33%> (+2.13%) ⬆️

... and 17 files with indirect coverage changes

@willyborankin
Copy link
Collaborator Author

now all tests passed

Copy link
Member

@peternied peternied left a comment

Choose a reason for hiding this comment

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

Nice work @willyborankin!

Overall comment, it looks like much of code you've added isn't getting registering code coverage hits - something might be wrong with the test execution, can you look into that?

@willyborankin
Copy link
Collaborator Author

willyborankin commented Feb 5, 2024

Hi @peternied, thanks for your feedback. I will reorganize the code a bit. The way I implemented the index initialization is a bit wrong. The initialization needs to be done by the generic executor and changing of the cluster state via it. The management executor has a 20-second timeout, so it could lead to problems if the index initialization takes more than 20 seconds.

@willyborankin willyborankin force-pushed the init-index-on-managed-node branch from 26e1adf to 416dcb8 Compare February 15, 2024 07:45
@willyborankin
Copy link
Collaborator Author

Hi @peternied, the latest version which includes:

  • Adding of configuration now use bulk update
  • Any node fails if it can't read/write configuration
  • Addressed all comments you mentioned.

I think we can extend tests for the functionality I added. Lets discuss additional tests.

@willyborankin willyborankin force-pushed the init-index-on-managed-node branch 3 times, most recently from 2ea90e4 to ea16e01 Compare February 15, 2024 09:48
@willyborankin willyborankin force-pushed the init-index-on-managed-node branch 5 times, most recently from 3cf6118 to b51cc85 Compare February 15, 2024 14:37
@willyborankin
Copy link
Collaborator Author

@peternied Looks like tests failures are note related. the new cluster permission appears:

cluster:monitor/term

@willyborankin willyborankin force-pushed the init-index-on-managed-node branch from b80d321 to 1a7560d Compare March 25, 2024 13:55
@willyborankin
Copy link
Collaborator Author

@peternied now all tests passed

peternied
peternied previously approved these changes Mar 25, 2024
peternied
peternied previously approved these changes Mar 25, 2024
@willyborankin willyborankin force-pushed the init-index-on-managed-node branch from dce3e8b to 60f56b2 Compare March 26, 2024 07:39
cwperks
cwperks previously approved these changes Mar 26, 2024
@peternied peternied dismissed their stale review March 26, 2024 16:31

I'd like to see better coverage in of buildDynamicConfiguration before merging

@willyborankin
Copy link
Collaborator Author

willyborankin commented Mar 26, 2024

@peternied I think coverage now around 99 or 98 % for the SecutyIndexHandler :-)

@willyborankin
Copy link
Collaborator Author

@peternied the final score is 87.6 which is good I think

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.

Changes look good to me! Thank you for this change and adding a comprehensive test suite @willyborankin!

@peternied peternied merged commit b0d26dd into opensearch-project:main Mar 27, 2024
82 checks passed
@willyborankin willyborankin added the backport 2.x backport to 2.x branch label Apr 15, 2024
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

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

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/security/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/security/backport-2.x
# Create a new branch
git switch --create backport/backport-4002-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 b0d26ddbfd584a76cb7eb48ee36c461fd0e9e19b
# Push it to GitHub
git push --set-upstream origin backport/backport-4002-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/security/backport-2.x

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

willyborankin added a commit to willyborankin/security that referenced this pull request Apr 15, 2024
Signed-off-by: Andrey Pleskach <[email protected]>
(cherry picked from commit b0d26dd)
willyborankin added a commit to willyborankin/security that referenced this pull request Apr 15, 2024
Signed-off-by: Andrey Pleskach <[email protected]>
(cherry picked from commit b0d26dd)
willyborankin added a commit to willyborankin/security that referenced this pull request Apr 15, 2024
Signed-off-by: Andrey Pleskach <[email protected]>
(cherry picked from commit b0d26dd)
dlin2028 pushed a commit to dlin2028/security that referenced this pull request May 1, 2024
@willyborankin willyborankin deleted the init-index-on-managed-node branch June 14, 2024 19:00
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
4 participants