-
Notifications
You must be signed in to change notification settings - Fork 35
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
AWS — added feature to read secrets from other accounts #57
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ case class AWSProviderSettings( | |
fileWriterOpts: Option[FileWriterOptions], | ||
defaultTtl: Option[Duration], | ||
endpointOverride: Option[String], | ||
altRegion: String | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
) | ||
|
||
import io.lenses.connect.secrets.config.AbstractConfigExtensions._ | ||
|
@@ -39,6 +40,8 @@ object AWSProviderSettings { | |
val authMode = | ||
getAuthenticationMethod(configs.getString(AWSProviderConfig.AUTH_METHOD)) | ||
|
||
val altRegion = configs.getString("aws.cross.account.region") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using the string |
||
|
||
if (authMode == AuthMode.CREDENTIALS) { | ||
if (accessKey.isEmpty) | ||
throw new ConnectException( | ||
|
@@ -59,6 +62,7 @@ object AWSProviderSettings { | |
defaultTtl = | ||
Option(configs.getLong(SECRET_DEFAULT_TTL).toLong).filterNot(_ == 0L).map(Duration.of(_, ChronoUnit.MILLIS)), | ||
endpointOverride, | ||
altRegion = altRegion | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,9 @@ import scala.util.Try | |
class AWSHelper( | ||
client: SecretsManagerClient, | ||
defaultTtl: Option[Duration], | ||
fileWriterCreateFn: () => Option[FileWriter], | ||
region: String, | ||
altRegion: String, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be made an Option |
||
fileWriterCreateFn: () => Option[FileWriter] | ||
)( | ||
implicit | ||
clock: Clock, | ||
|
@@ -48,12 +50,26 @@ class AWSHelper( | |
private val objectMapper = new ObjectMapper() | ||
|
||
// get the key value and ttl in the specified secret | ||
override def lookup(secretId: String): Either[Throwable, ValueWithTtl[Map[String, String]]] = | ||
override def lookup(secretId: String): Either[Throwable, ValueWithTtl[Map[String, String]]] = { | ||
val secretName = getSecretName(secretId) | ||
for { | ||
secretTtl <- getTTL(secretId) | ||
secretValue <- getSecretValue(secretId) | ||
secretTtl <- getTTL(secretName) | ||
secretValue <- getSecretValue(secretName) | ||
parsedSecretValue <- parseSecretValue(secretValue) | ||
} yield ValueWithTtl(secretTtl, parsedSecretValue) | ||
} | ||
|
||
private def getSecretName(secretId: String): String = { | ||
val hasAccount = secretId.indexOf("$") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could this be
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This variable is named as a boolean (hasAccount). This and the > 1 condition below should be merged so this is a boolean variable. |
||
if (hasAccount > -1) { | ||
val secret_region = if (hasAccount > -1 && altRegion.length > 0) altRegion else region | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't use underscores in variable names, for consistency these should be camelCase There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the hasAccount > -1 condition here is unnecessary as you're already in a block `if (hasAccount > -1) |
||
val secret_array = secretId.split("\\$") | ||
s"arn:aws:secretsmanager:${secret_region}:${secret_array(0)}:secret:${secret_array(1)}" | ||
} | ||
else { | ||
secretId | ||
} | ||
} | ||
|
||
// determine the ttl for the secret | ||
def getTTL( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I general I'm not sure I understand the need for the alt.region property as
it is always used wherever region is used and simply overrides it - I think this can be removed in favour of just changing the existing region property in connector configuration?
the condition that activates the new configuration is actually only activated based on the presence of an $ in the secret id, so I don't think any configuration is necessary here.