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

UI: Fix enabling replication capabilities bug #28371

Merged

Conversation

hellobontempo
Copy link
Contributor

@hellobontempo hellobontempo commented Sep 11, 2024

Description

A user with the policy below (which is used in this tutorial) was unable to enable replication in the GUI because the UI wasn't checking specifically for /dr/ or /performance/ in the original capabilities check.

// original check, path didn't include type
canEnablePrimary: this.store
        .findRecord('capabilities', 'sys/replication/primary/enable')
        .then((c) => c.canUpdate),
      canEnableSecondary: this.store
        .findRecord('capabilities', 'sys/replication/secondary/enable')
        .then((c) => c.canUpdate),

Now type is included in the path passed to the capabilities endpoint which hides or shows "Enable" accordingly. If there's a problem reading capabilities, then the default is true because the backend can be used as a fallback to gate a user who does not have the correct permissions.

I will open a manual backport to address this fix in 1.16 and 1.17 because the capabilities service is new and was added in 1.18


📸 The left is before the fix, and on the right is after.

Both browsers the user is logged in with the policy below.
Screenshot 2024-09-11 at 5 52 56 PM

# To enable DR primary
path "sys/replication/dr/primary/enable" {
  capabilities = ["create", "update"]
}

# To generate a secondary token required to add a DR secondary
path "sys/replication/dr/primary/secondary-token" {
  capabilities = ["create", "update", "sudo"]
}

# To create ACL policies
path "sys/policies/acl/*" {
  capabilities = ["create", "update", "list"]
}

# Create a token role for batch DR operation token
path "auth/token/roles/*" {
  capabilities = ["create", "update"]
}

# Create a token
path "auth/token/create" {
  capabilities = ["create", "update"]
}

# To demote the primary to secondary
path "sys/replication/dr/primary/demote" {
  capabilities = ["create", "update"]
}

# To enable DR secondary
path "sys/replication/dr/secondary/enable" {
  capabilities = ["create", "update"]
}

# To generate an operation token
path "sys/replication/dr/secondary/generate-operation-token/*" {
  capabilities = ["create", "update"]
}

# To promote the secondary cluster to be primary
path "sys/replication/dr/secondary/promote" {
  capabilities = ["create", "update"]
}

# To update the assigned primary cluster
path "sys/replication/dr/secondary/update-primary" {
  capabilities = ["create", "update"]
}

# If you choose to disable the original primary cluster post-recovery
path "sys/replication/dr/primary/disable" {
  capabilities = ["create", "update"]
}

TODO only if you're a HashiCorp employee

  • Backport Labels: If this PR is in the ENT repo and needs to be backported, backport
    to N, N-1, and N-2, using the backport/ent/x.x.x+ent labels. If this PR is in the CE repo, you should only backport to N, using the backport/x.x.x label, not the enterprise labels.
    • If this fixes a critical security vulnerability or severity 1 bug, it will also need to be backported to the current LTS versions of Vault. To ensure this, use all available enterprise labels.
  • ENT Breakage: If this PR either 1) removes a public function OR 2) changes the signature
    of a public function, even if that change is in a CE file, double check that
    applying the patch for this PR to the ENT repo and running tests doesn't
    break any tests. Sometimes ENT only tests rely on public functions in CE
    files.
  • Jira: If this change has an associated Jira, it's referenced either
    in the PR description, commit message, or branch name.
  • RFC: If this change has an associated RFC, please link it in the description.
  • ENT PR: If this change has an associated ENT PR, please link it in the
    description. Also, make sure the changelog is in this PR, not in your ENT PR.

@hellobontempo hellobontempo added this to the 1.18.0-rc milestone Sep 11, 2024
@hellobontempo hellobontempo requested a review from a team as a code owner September 11, 2024 19:54
@github-actions github-actions bot added the hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed label Sep 11, 2024
Copy link

Build Results:
All builds succeeded! ✅

Copy link

github-actions bot commented Sep 11, 2024

CI Results:
All Go tests succeeded! ✅

@@ -14,6 +13,23 @@ export default Route.extend(ClusterRoute, {
store: service(),
auth: service(),
router: service(),
capabilities: service(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about not using the new service here so that it more cleanly backported to older versions (this only exists in 1.18 so far), BUT the service is nice because we only make one request for all of these capabilities instead of a request for each path which I think is a win! 🙌

Comment on lines +13 to +17
if (this.modeSelection === 'dr') {
// returns canEnablePrimaryDr or canEnableSecondaryDr
return `canEnable${type}Dr`;
}
if (this.modeSelection === 'performance') {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to explicitly check for each mode instead of do a ternary statement since that'd mean if there wasn't a mode we'd fallback on a whichever was the falsy capability which didn't feel like the most stable thing to do.

@@ -0,0 +1,3 @@
```release-note:bug
ui: Fix UI improperly checking capabilities for enabling performance and dr replication
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This wording feels strange? Open to alternatives!

* />
* ```
*
* @param {string} replicationMode - should be one of "dr" or "performance"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🔤 alphabetized 🤓

const { cluster, replicationMode } = this.args;
let perm;
if (replicationMode === 'dr') {
// returns canEnablePrimaryDr or canEnableSecondaryDr
Copy link
Contributor Author

Choose a reason for hiding this comment

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

added these comments so future devs see they are used here if performing a global search for the capabilities defined in the route

canEnablePrimaryDr,
canEnableSecondaryDr,
canEnablePrimaryPerformance,
canEnableSecondaryPerformance,

enablePath('performance', 'secondary'),
]);
return {
canEnablePrimaryDr: perms[enablePath('dr', 'primary')].canUpdate,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

originally I wrote all these variables as canEnableDrPrimary or canEnablePerformancePrimary but I found it easier to read with the type at the end and the cluster in the middle. Dr seemed to get lost in the middle there

Copy link
Collaborator

@hashishaw hashishaw left a comment

Choose a reason for hiding this comment

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

Beautiful ✨

@hashishaw hashishaw merged commit 49b46ea into main Sep 12, 2024
31 checks passed
@hashishaw hashishaw deleted the ui/VAULT-30458/fix-enabling-replication-capabilities-bug branch September 12, 2024 13:51
@hashishaw hashishaw modified the milestones: 1.18.0-rc, 1.16.10 Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/ent/1.16.x+ent Changes are backported to 1.16.x+ent backport/1.17.x backport/1.18.x hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants