-
Notifications
You must be signed in to change notification settings - Fork 4k
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
(secretsmanager): secret_name returns the end of the ARN with 6 character suffix #11727
Comments
Hi @melodyyangaws , Any particular reason you're using the
This is impossible to do generically with built-in CloudFormation tools, but if you happen to know the format of the import { Fn } from '@aws-cdk/core';
const secretNameParts = Fn.split('-', my_secret.secret_name);
const secretNameWithoutSuffix = Fn.join('-', [Fn.select(0, secretNameParts), Fn.select(1, secretNameParts)]); |
Hi @njlynch, thank you so much, your suggestion worked! |
…der feature flag) Proper (tokenized) secret names for owned secrets was introduced in #11202. This caused `Secret.secretName` to return the full resource name (secret name + suffix) for owned secrets. This was done to ensure that the secretName was a Tokenized value that would create a dependency between the Secret and its consumer. However, Secrets Manager's DescribeSecret API does not accept the resourceName as an input; it accepts the full ARN, a partial ARN (without the suffix), or the secret name (without the suffix). This leads to several integrations with other services or custom scripts to fail when using the secretName from an owned Secret. For owned secrets, we can formulate how to parse the resourceName to get the secretName based on either (a) knowing the secret name or (b) knowing the format that CloudFormation uses when secret names aren't specified. This fix introduces proper parsing of secret names for owned secrets (behind a feature flag). BREAKING CHANGE: (feature flag) Secret.secretName for owned secrets will now only the secret name (without suffix) and not the full resource name. This is enabled through the `@aws-cdk/secretsmanager:parseOwnedSecretName` flag. fixes #11727
…der feature flag) Proper (tokenized) secret names for owned secrets was introduced in #11202. This caused `Secret.secretName` to return the full resource name (secret name + suffix) for owned secrets. This was done to ensure that the secretName was a Tokenized value that would create a dependency between the Secret and its consumer. However, Secrets Manager's DescribeSecret API does not accept the resourceName as an input; it accepts the full ARN, a partial ARN (without the suffix), or the secret name (without the suffix). This leads to several integrations with other services or custom scripts to fail when using the secretName from an owned Secret. For owned secrets, we can parse the resourceName to get the secretName based on either (a) knowing the secret name or (b) knowing the format that CloudFormation uses when secret names aren't specified. This fix introduces proper parsing of secret names for owned secrets (behind a feature flag). BREAKING CHANGE: (feature flag) Secret.secretName for owned secrets will now only the secret name (without suffix) and not the full resource name. This is enabled through the `@aws-cdk/secretsmanager:parseOwnedSecretName` flag. fixes #11727
…der feature flag) Proper (tokenized) secret names for owned secrets was introduced in #11202. This caused `Secret.secretName` to return the full resource name (secret name + suffix) for owned secrets. This was done to ensure that the secretName was a Tokenized value that would create a dependency between the Secret and its consumer. However, Secrets Manager's DescribeSecret API does not accept the resourceName as an input; it accepts the full ARN, a partial ARN (without the suffix), or the secret name (without the suffix). This leads to several integrations with other services or custom scripts to fail when using the secretName from an owned Secret. For owned secrets, we can parse the resourceName to get the secretName based on either (a) knowing the secret name or (b) knowing the format that CloudFormation uses when secret names aren't specified. This fix introduces proper parsing of secret names for owned secrets (behind a feature flag). BREAKING CHANGE: (feature flag) Secret.secretName for owned secrets will now only the secret name (without suffix) and not the full resource name. This is enabled through the `@aws-cdk/secretsmanager:parseOwnedSecretName` flag. fixes #11727
As a general rule, attributes of a construct (e.g., things assigned at deploy time) are Tokens, which are placeholders that can't be directly manipulated. The only way to handle them is through Cfn-native functions. For what it's worth, while I think you should use |
HI @njlynch , I am new to EKS, maybe I am wrong. The |
…der feature flag) (#11736) Proper (tokenized) secret names for owned secrets was introduced in #11202. This caused `Secret.secretName` to return the full resource name (secret name + suffix) for owned secrets. This was done to ensure that the secretName was a Tokenized value that would create a dependency between the Secret and its consumer. However, Secrets Manager's DescribeSecret API does not accept the resourceName as an input; it accepts the full ARN, a partial ARN (without the suffix), or the secret name (without the suffix). This leads to several integrations with other services or custom scripts to fail when using the secretName from an owned Secret. For owned secrets, we can parse the resourceName to get the secretName based on either (a) knowing the secret name or (b) knowing the format that CloudFormation uses when secret names aren't specified. This fix introduces proper parsing of secret names for owned secrets (behind a feature flag). BREAKING CHANGE: (feature flag) Secret.secretName for owned secrets will now only the secret name (without suffix) and not the full resource name. This is enabled through the `@aws-cdk/secretsmanager:parseOwnedSecretName` flag. fixes #11727 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
Hello @njlynch I think this is still an issue and we can't use ARN either. In our case, we're using the path to the secret as the (plain) value of an SSM parameter. That way we can organize our SSM parameters in a hierarchical way (as controlled by a configuration class structure) and use indirection to do a second lookup when the value is a reference to a secret. Given this secret: ads_master_secret = aws_secretsmanager.Secret(
self,
id="AdsMasterSecret",
generate_secret_string=aws_secretsmanager.SecretStringGenerator(
secret_string_template=json.dumps({"username": ads_master_username}),
generate_string_key="password",
exclude_punctuation=True,
),
) and this SSM parameter: aws_ssm.StringParameter(
self,
id="AdsMasterCredentialsSSMParam",
string_value="/aws/reference/secretsmanager/" + ads_master_secret.secret_name,
parameter_name="/databases/main/password",
) and this "@aws-cdk/secretsmanager:parseOwnedSecretName": "true" We then load the config this way (at runtime): log.debug("Looking for parameter {}", path);
val v = client.getParameter(req -> req.name(path).withDecryption(true)).parameter().value();
if (v.startsWith(SECRET_PATH)) { // /aws/reference/secretsmanager/
// If the parameter refers to a secrets path, perform another lookup to get that value
log.debug("Looking for secret {}...", v);
val secret = client.getParameter(req -> req.name(v).withDecryption(true)).parameter().value();
val creds = new ObjectMapper().readValue(secret, Credentials.class);
map.put(path, creds.getPassword());
} else {
map.put(path, v);
} but are getting the error:
even though IAM stuff should be set up correctly... (and as you can see, it's using the full suffix) Unless there's a better way of bridging the "flat" nature of the secrets manager with the "tree" of SSM parameters? |
Hello @njlynch I have checked and the Feature toggle I simply do not understand what is happening there. Regards, |
Reopen the issue #11573
Need to create an external secret in EKS, which is retrieved from secrets manager. Currently, CDK returns a secret name with secrets manager's 6 character suffix. Hopefully it can be fixed. Or a workaround would be appreciated.
It caused the error:
{"level":50,"time":1606359303455,"pid":17,"hostname":"external-secrets-kubernetes-external-secrets-5648bf6544-p87vp","message":"Secrets Manager can't find the specified secret.","code":"ResourceNotFoundException"
Reproduction Steps
my_secret = Secret(self, 'xx', generate_secret_string=SecretStringGenerator(secret_string_template=json.dumps({'username': 'tester'}), generate_string_key="password") )
The content of ex-secret.yaml:
What did you expect to happen?
I want to get the correct secret name that matches the name in secrets manager console.
What actually happened?
in CDK,
my_secret.secret_name
returns the end of full ARN with 6 character suffix, ie.jHubSecretArn6E48ECC3-0YhYd3BbaFH5-qeNyUO
. The external secret object in EKS is actually expectingjHubSecretArn6E48ECC3-0YhYd3BbaFH5
Environment
Other
in CFN, it looks like this. can we further split it by '-', then take the first & second parts to construct the secret name?
"Value": {
"Fn::Select": [6,{"Fn::Split": [":",{ "Ref": "jHubSecretArn6E48ECC3" }]}]
}
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: