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

feat: Vault tokens are now identity-based instead of anonymous #4327

Merged
merged 1 commit into from
Feb 8, 2023
Merged

feat: Vault tokens are now identity-based instead of anonymous #4327

merged 1 commit into from
Feb 8, 2023

Conversation

bnevis-i
Copy link
Collaborator

@bnevis-i bnevis-i commented Feb 6, 2023

This is an internal refactoring of security-secretstore-setup, security-file-token-provider, and security-spiffe-token-provider to generate Vault tokens that are based on a Vault identity instead of being anonymous tokens with an attached ACL.

The consequence of this refactoring is that the token issuing components of EdgeX run with fewer required privileges than before, and it is possible to ask Vault for a verifiable JWT-based identity assertion of an EdgeX service.

This change should be completely transparent to all existing EdgeX services.

Signed-off-by: Bryon Nevis [email protected]

PR Checklist

Please check if your PR fulfills the following requirements:

  • I am not introducing a breaking change (if you are, flag in conventional commit message with BREAKING CHANGE: describing the break)
  • I am not introducing a new dependency (add notes below if you are)
  • I have added unit tests for the new feature or bug fix (if not, why?)
  • I have fully tested (add details below) this the new feature or bug fix (if not, why?)
  • I have opened a PR for the related docs change (if not, why?) n/a

Testing Instructions

# in edge-go
make clean_docker_base docker_base docker
# in compose-builder
make run dev ds-virtual
make get-token
# Go to localhost:4000 with the above token and make sure everything runs as usual

New Dependency Instructions (If applicable)

@bnevis-i bnevis-i added the 1-low priority denoting isolated changes label Feb 6, 2023
@bnevis-i bnevis-i added this to the Minnesota milestone Feb 6, 2023
Comment on lines +43 to +46
#PrivilegedTokenPath = "UNUSED"
#ConfigFile = "UNUSED"
#OutputDir = "UNUSED"
#OutputFilename = "UNUSED"
Copy link
Contributor

Choose a reason for hiding this comment

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

if we remove this, shouldn't it become breaking changes in terms of update pov?

Copy link
Collaborator Author

@bnevis-i bnevis-i Feb 6, 2023

Choose a reason for hiding this comment

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

What this is actually doing is reusing the configuration.toml snippet from security-file-token-provider except that we don't need all of the parameters, just some of them (like the TTL on the vault token and JWT). I'm just making it clear that we don't use these parameters in spiffe-token-provider.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

Comment on lines 13 to 16
//
// SPDX-License-Identifier: Apache-2.0'
//
package fileprovider
package common
Copy link
Contributor

Choose a reason for hiding this comment

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

update license header for year 2023

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh no! Just pushed a commit to update copyright dates.

// Set a meta property that consuming serices can use to automatically scope secret queries
createTokenParameters["meta"] = map[string]interface{}{
"edgex-service-name": serviceName,
randomPassword, err := credentialGenerator.Generate(context.TODO())
Copy link
Contributor

Choose a reason for hiding this comment

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

what is context.TODO()?

Copy link
Collaborator Author

@bnevis-i bnevis-i Feb 6, 2023

Choose a reason for hiding this comment

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

TODO returns a non-nil, empty Context. Code should use context.TODO when it's unclear which Context to use or it is not yet available (because the surrounding function has not yet been extended to accept a Context parameter)

The original implementation of the credential generator used a key derivation scheme that derived multiple passwords from the same base secret (that code used Context). We later changed it to just do random bits in base64. Context is no longer used, but left in the API to avoid having to modify a million places in the code. Per GO BKM, never pass a nil Context.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for details explanation 👍

@bnevis-i
Copy link
Collaborator Author

bnevis-i commented Feb 7, 2023

Resolved merge conflict in go.mod.

Comment on lines +124 to +134
if identityId != "" {
err = m.secretStoreClient.DeleteIdentity(m.privilegedToken, username)
if err != nil {
return err
}
}

err = m.secretStoreClient.DeleteUser(m.privilegedToken, m.userPassMountPoint, username)
if err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

should we make this transactional or atomic? if deleting user somehow failed then you lost identity for that user isn't it?

Copy link
Collaborator Author

@bnevis-i bnevis-i Feb 8, 2023

Choose a reason for hiding this comment

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

I think its ok. The ACL is attached to the identity so if you delete the identity the user is really gone. You could attempt to log in as the user, but it would error out as it isn't bound to anything. Moreover, if you recreated the user it would overwrite the identity and/or login, so a partial deletion would take up space but that's about it.

And if you redeleted the user due to an error, the lookupidentity would not find an identity and it would proceed to delete the login.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, good to know that creating user would get a new identity.

This is an internal refactoring of security-secretstore-setup,
security-file-token-provider, and security-spiffe-token-provider
to generate Vault tokens that are based on a Vault identity
instead of being anonymous tokens with an attached ACL.

The consequence of this refactoring is that the token
issuing components of EdgeX run with fewer required privileges
than before, and it is possible to ask Vault for a
verifiable JWT-based identity assertion of an EdgeX service.

Signed-off-by: Bryon Nevis <[email protected]>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 8, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@@ -157,12 +157,15 @@ func TestNoDefaultsCustomPolicy(t *testing.T) {
mockAuthTokenLoader.On("Load", privilegedTokenPath).Return("fake-priv-token", nil)

expectedService1Policy := `{"path":{"secret/non/standard/location/*":{"capabilities":["list","read"]}}}`
expectedService1Parameters := makeMetaServiceName("myservice")
//expectedService1Parameters := makeMetaServiceName("myservice")
Copy link
Contributor

Choose a reason for hiding this comment

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

remove the dead code

@bnevis-i bnevis-i merged commit fd143bc into edgexfoundry:main Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1-low priority denoting isolated changes security-services
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants