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

Add cloud secret managers #2974

Merged
merged 18 commits into from
Nov 7, 2024
Merged

Add cloud secret managers #2974

merged 18 commits into from
Nov 7, 2024

Conversation

tomasz-sadura
Copy link
Contributor

@tomasz-sadura tomasz-sadura commented Oct 31, 2024

Added impl. for AWS, GCP and Azure secrets managers. The code is in common-go to reuse for linter.

Copy link
Member

@nicolaferraro nicolaferraro left a comment

Choose a reason for hiding this comment

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

Very nice.
In cloud, we need to use the same lookup logic in the API linter, is it possible (also as followup) to expose here some public service that we can reuse?

I'm not sure if the cloud project can be depend on connect tbh...

@nicolaferraro
Copy link
Member

I'm thinking we might move the lookup code here: https://github.com/redpanda-data/common-go

@tomasz-sadura
Copy link
Contributor Author

Yea. So the code in RPCN currently reads secret values, and the RPCN requires perms to do so. If we want to check secrets from the API we need some perms here as well. On one hand we do not need to read the secret, just check if it exists. On the other hand, we also extract JSON fields form the secret value, so we actually need to read it.
So finally - yes, we can have linter to check the secrets and add permissions for the API to do so.

}, nil
}

func (a *awsSecretsManager) getSecretValue(key string) (string, bool) {
Copy link
Member

Choose a reason for hiding this comment

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

We can probably pass context and use the client's GetSecretValueWithContext() method.
https://docs.aws.amazon.com/sdk-for-go/api/service/secretsmanager/#SecretsManager.GetSecretValueWithContext

return "", false
}
key = strings.TrimPrefix(key, secretPrefix)
parts := strings.SplitN(key, ".", 2)
Copy link
Member

Choose a reason for hiding this comment

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

can we maybe comment some of this stuff so it's clearer why we have the prefix and what's being done here

return secretManager.lookup, nil
}

func trimLeftSlash(path string) string {
Copy link
Member

@bojand bojand Nov 1, 2024

Choose a reason for hiding this comment

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

maybe it's just me but it seems weird and excessive to wrap a single line of code into a new function that returns the same return value as the called function.

strings.TrimPrefix(path, "/")

seems clear enough not to have to warrant a name like trimLeftSlash

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea, at first this was meant to be reused, but then moved to a common file. Indeed no longer sense for it, inlined.

go.mod Outdated
@@ -27,6 +27,7 @@ require (
github.com/PaesslerAG/jsonpath v0.1.1
github.com/apache/pulsar-client-go v0.13.1
github.com/aws/aws-lambda-go v1.47.0
github.com/aws/aws-sdk-go v1.50.36
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does the v2 one have the APIs you need?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We're not going to use redis in cloud - can we keep this implementation in this repo? In case others want to add stuff - we should decouple cloud from whatever the community wants to add.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is that what you mean?: 667da58

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Kind of - but now the cloud secret managers are removed? Also the lookup thing is a little clunky because it's not used here (but I guess will be in linting).

Maybe the right thing here is to do something like this:

Make LookupFn a single method interface instead. All the implementations in connect only need to implement that single lookup function. The switch statement of which URNs are supported is in this repo.

Secondarily in the common-go repo, have the implementations of the cloud secret managers that are used here in the switch statement. The ones in common-go will satisfy an additional interface (ontop of the LookupFn method) that provides existing. The switch statement for URNs and linting can be duplicated in cloudv2 since the logic to determine which secret manager to use will be based on the cloud account, then we won't be required to stuff the parameters into a URN (which is really only an artifact of it being a commandline arg, but we don't need to do that when linting in the connect api).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. It makes perfect sense. Wanted to reuse the secret provider creation mechanism (from URL), but this way looks a lot simpler, thanks!

Copy link
Collaborator

@rockwotj rockwotj left a comment

Choose a reason for hiding this comment

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

Seems OK to me - I would prefer the logic to setup cloud config from a URL be in this repo.

I will let @Jeffail make the final call here.

Copy link
Collaborator

@Jeffail Jeffail left a comment

Choose a reason for hiding this comment

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

Ideally I'd want the secret manager clients to be within this repo, or at least that the library we're referencing (common-go) to be tagged at a stable version. The problem with this arrangement is that breaking changes in common-go could break custom builds of RPCN if they end up with an incompatible dependency graph. It's not likely but I've seen it happen in the wild already.

In the interest of getting a release out this evening I think this is fine to merge and tag, but it'd be good to do the above in time for the next release if possible.

@Jeffail Jeffail merged commit cbafa38 into main Nov 7, 2024
3 checks passed
@Jeffail Jeffail deleted the cloud-secret-managers branch November 7, 2024 18:24
@tomasz-sadura
Copy link
Contributor Author

Just tagged it but was 2 minutes late. Feel free to update the dep to v0.1.0.

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.

5 participants