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

rbd: create token and use it for vault SA everytime possible #3377

Merged
merged 1 commit into from
Sep 9, 2022

Conversation

saiprashanth173
Copy link
Contributor

Signed-off-by: Prashanth Dintyala vdintyala@nvidia.com

Describe what this PR does

Create short lived service account tokens and use them for vault SA approach even for K8s version <1.24; fall back to using token obtained from services account's secret reference (if exists).

Related issues

Fixes: #3360


Show available bot commands

These commands are normally not required, but in case of issues, leave any of
the following bot commands in an otherwise empty comment in this PR:

  • /retest ci/centos/<job-name>: retest the <job-name> after unrelated
    failure (please report the failure too!)
  • /retest all: run this in case the CentOS CI failed to start/report any test
    progress or results

@mergify mergify bot added the component/rbd Issues related to RBD label Sep 7, 2022
internal/kms/vault_sa.go Outdated Show resolved Hide resolved
Madhu-1
Madhu-1 previously approved these changes Sep 8, 2022
Copy link
Contributor

@Rakshith-R Rakshith-R left a comment

Choose a reason for hiding this comment

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

I think we would be completely missing the err which may have happened during createToken.
if it was something that would be helpful.

I'd prefer we make the requested changes, so we can capture both the errors if they occur,

wdyt @Madhu-1 @saiprashanth173 ?

Comment on lines +300 to +303
token, err := kms.createToken(sa, c)
if err == nil {
return token, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
token, err := kms.createToken(sa, c)
if err == nil {
return token, nil
}
token, createTokenErr := kms.createToken(sa, c)
if createTokenErr == nil {
return token, nil
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure what the change above will cover. If we want to be more specific. Continue to fetch token from the SA only if kubernetes doesn't support TokeRequest API else return all other errors.

Copy link
Contributor

@Rakshith-R Rakshith-R Sep 9, 2022

Choose a reason for hiding this comment

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

apologies, the other part of the requested changes was not posted by mistake.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch! Yes it makes sense to include this error as part of the final error. I updated the code to include it in the error being returned.

@@ -310,7 +314,7 @@ func (kms *vaultTenantSA) getToken() (string, error) {
}
}

return kms.createToken(sa, c)
return "", fmt.Errorf("failed to find token in ServiceAccount %s/%s", kms.Tenant, kms.tenantSAName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return "", fmt.Errorf("failed to find token in ServiceAccount %s/%s", kms.Tenant, kms.tenantSAName)
err = fmt.Errorf("failed to find token in ServiceAccount %s/%s", kms.Tenant, kms.tenantSAName)
if createTokenErr != nil {
err = fmt.Errorf(%w and failed to create token: %w",err, createTokenErr)
}
return "", err

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We only reach here if createTokenErr is not nil. I felt if here is redundant. Included it as part of final error.

Comment on lines +300 to +303
token, err := kms.createToken(sa, c)
if err == nil {
return token, nil
}
Copy link
Contributor

@Rakshith-R Rakshith-R Sep 9, 2022

Choose a reason for hiding this comment

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

apologies, the other part of the requested changes was not posted by mistake.

use TokenRequest API by default for vault SA even with K8s versions < 1.24

Signed-off-by: Prashanth Dintyala <vdintyala@nvidia.com>
Copy link
Contributor

@Rakshith-R Rakshith-R left a comment

Choose a reason for hiding this comment

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

Thanks ! ,
LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/rbd Issues related to RBD
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Supporting TokenRequest API for vault tenant SA & K8s versions < 1.24
5 participants