Skip to content

Commit 97a7aaa

Browse files
feat(entities-vaults): add aws vault fields
1 parent d2ca0b8 commit 97a7aaa

File tree

3 files changed

+99
-6
lines changed

3 files changed

+99
-6
lines changed

packages/entities/entities-vaults/src/components/VaultForm.vue

+76-5
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,43 @@
189189
required
190190
width="100%"
191191
/>
192+
<KInput
193+
v-model.trim="configFields[VaultProviders.AWS].endpoint_url"
194+
autocomplete="off"
195+
data-testid="vault-form-config-aws-endpoint_url"
196+
:is-readonly="form.isReadonly"
197+
:label="t('form.config.aws.fields.endpoint_url.label')"
198+
:label-attributes="{
199+
info: t('form.config.aws.fields.endpoint_url.tooltip'),
200+
tooltipAttributes: { maxWidth: '400px' },
201+
}"
202+
type="text"
203+
/>
204+
<KInput
205+
v-model.trim="configFields[VaultProviders.AWS].assume_role_arn"
206+
autocomplete="off"
207+
data-testid="vault-form-config-aws-assume_role_arn"
208+
:is-readonly="form.isReadonly"
209+
:label="t('form.config.aws.fields.assume_role_arn.label')"
210+
:label-attributes="{
211+
info: t('form.config.aws.fields.assume_role_arn.tooltip'),
212+
tooltipAttributes: { maxWidth: '400px' },
213+
}"
214+
type="text"
215+
/>
216+
<KInput
217+
v-model.trim="configFields[VaultProviders.AWS].role_session_name"
218+
autocomplete="off"
219+
data-testid="vault-form-config-aws-role_session_name"
220+
:is-readonly="form.isReadonly"
221+
:label="t('form.config.aws.fields.role_session_name.label')"
222+
:label-attributes="{
223+
info: t('form.config.aws.fields.role_session_name.tooltip'),
224+
tooltipAttributes: { maxWidth: '400px' },
225+
}"
226+
required
227+
type="text"
228+
/>
192229
</div>
193230

194231
<!-- GCP fields -->
@@ -293,7 +330,10 @@
293330
required
294331
width="100%"
295332
/>
296-
<div v-if="configFields[VaultProviders.HCV].auth_method === VaultAuthMethods.TOKEN">
333+
<div
334+
v-if="configFields[VaultProviders.HCV].auth_method === VaultAuthMethods.TOKEN"
335+
class="vault-form-config-auth-method-container"
336+
>
297337
<KInput
298338
v-model.trim="configFields[VaultProviders.HCV].token"
299339
autocomplete="off"
@@ -304,7 +344,10 @@
304344
type="text"
305345
/>
306346
</div>
307-
<div v-else-if="configFields[VaultProviders.HCV].auth_method === VaultAuthMethods.K8S">
347+
<div
348+
v-else-if="configFields[VaultProviders.HCV].auth_method === VaultAuthMethods.K8S"
349+
class="vault-form-config-auth-method-container"
350+
>
308351
<KInput
309352
v-model.trim="configFields[VaultProviders.HCV].kube_role"
310353
autocomplete="off"
@@ -332,7 +375,10 @@
332375
type="text"
333376
/>
334377
</div>
335-
<div v-else-if="configFields[VaultProviders.HCV].auth_method === VaultAuthMethods.APP_ROLE">
378+
<div
379+
v-else-if="configFields[VaultProviders.HCV].auth_method === VaultAuthMethods.APP_ROLE"
380+
class="vault-form-config-auth-method-container"
381+
>
336382
<KInput
337383
v-model.trim="configFields[VaultProviders.HCV].approle_auth_path"
338384
autocomplete="off"
@@ -587,6 +633,9 @@ const configFields = reactive<ConfigFields>({
587633
} as KongVaultConfig,
588634
[VaultProviders.AWS]: {
589635
region: '',
636+
endpoint_url: '',
637+
assume_role_arn: '',
638+
role_session_name: 'KongVault',
590639
} as AWSVaultConfig,
591640
[VaultProviders.GCP]: {
592641
project_id: '',
@@ -625,6 +674,9 @@ const originalConfigFields = reactive<ConfigFields>({
625674
} as KongVaultConfig,
626675
[VaultProviders.AWS]: {
627676
region: '',
677+
endpoint_url: '',
678+
assume_role_arn: '',
679+
role_session_name: 'KongVault',
628680
} as AWSVaultConfig,
629681
[VaultProviders.GCP]: {
630682
project_id: '',
@@ -794,12 +846,23 @@ const isVaultConfigValid = computed((): boolean => {
794846
}).length
795847
}
796848
849+
// AWS Vault fields logic
850+
if (vaultProvider.value === VaultProviders.AWS) {
851+
return !Object.keys(configFields[VaultProviders.AWS]).filter(key => {
852+
// endpoint_url, assume_role_arn and ttl fields are optional
853+
if (['endpoint_url', 'assume_role_arn', 'ttl', 'neg_ttl', 'resurrect_ttl'].includes(key)) {
854+
return false
855+
}
856+
return !(configFields[vaultProvider.value] as AWSVaultConfig)[key as keyof AWSVaultConfig]
857+
}).length
858+
}
859+
797860
return !Object.keys(configFields[vaultProvider.value]).filter(key => {
798861
// ttl fields are optional
799862
if (['ttl', 'neg_ttl', 'resurrect_ttl'].includes(key)) {
800863
return false
801864
}
802-
return !(configFields[vaultProvider.value] as KongVaultConfig | AWSVaultConfig | GCPVaultConfig)[key as keyof (KongVaultConfig | AWSVaultConfig | GCPVaultConfig)]
865+
return !(configFields[vaultProvider.value] as KongVaultConfig | GCPVaultConfig)[key as keyof (KongVaultConfig | GCPVaultConfig)]
803866
}).length
804867
})
805868
const isFormValid = computed((): boolean => !!form.fields.prefix && isVaultConfigValid.value)
@@ -860,11 +923,19 @@ const getPayload = computed((): Record<string, any> => {
860923
tenant_id: (configFields[vaultProvider.value] as AzureVaultConfig).tenant_id || null,
861924
}
862925
926+
const awsConfig = {
927+
...configFields[vaultProvider.value],
928+
endpoint_url: (configFields[vaultProvider.value] as AWSVaultConfig).endpoint_url || null,
929+
assume_role_arn: (configFields[vaultProvider.value] as AWSVaultConfig).assume_role_arn || null,
930+
}
931+
863932
let config: VaultPayload['config'] = configFields[vaultProvider.value]
864933
if (vaultProvider.value === VaultProviders.HCV) {
865934
config = hcvConfig
866935
} else if (vaultProvider.value === VaultProviders.AZURE) {
867936
config = azureConfig
937+
} else if (vaultProvider.value === VaultProviders.AWS) {
938+
config = awsConfig
868939
}
869940
870941
let ttlFields = {}
@@ -981,7 +1052,7 @@ const saveFormData = async (): Promise<void> => {
9811052
}
9821053
9831054
&-config-fields-container {
984-
> *, div > * {
1055+
> *, .vault-form-config-auth-method-container > * {
9851056
&:not(:first-child) {
9861057
margin-top: $kui-space-80;
9871058
}

packages/entities/entities-vaults/src/locales/en.json

+12
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,18 @@
167167
"location": "US West"
168168
}
169169
}
170+
},
171+
"endpoint_url": {
172+
"label": "Endpoint URL",
173+
"tooltip": "The AWS SecretsManager service endpoint url. If not specified, the value used by vault will be the official AWS SecretsManager service url which is `https://secretsmanager.<region>.amazonaws.com`. You can specify a complete URL(including the \"http/https\" scheme) to override the endpoint that vault will connect to."
174+
},
175+
"assume_role_arn": {
176+
"label": "Assume Role ARN",
177+
"tooltip": "The target AWS IAM role ARN that will be assumed. Typically this is used for operating between multiple roles or cross-accounts. If you are not using assume role you should not specify this value."
178+
},
179+
"role_session_name": {
180+
"label": "Role Session Name",
181+
"tooltip": "The role session name used for role assuming."
170182
}
171183
}
172184
},

packages/entities/entities-vaults/src/types/vault-form.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ export interface KongVaultConfig {
4747

4848
export interface AWSVaultConfig {
4949
region: string
50+
endpoint_url?: string
51+
assume_role_arn?: string
52+
role_session_name: string
5053
ttl?: number
5154
neg_ttl?: number
5255
resurrect_ttl?: number
@@ -107,12 +110,19 @@ export interface AzureVaultConfigPayload extends Omit<AzureVaultConfig, 'client_
107110
tenant_id?: string | null
108111
}
109112

113+
// allow for nullish values in payload because Kong Admin API treats null as an empty value
114+
// in case it's an empty string, it will be treated as a value and must have length > 0
115+
export interface AWSVaultConfigPayload extends Omit<AWSVaultConfig, 'endpoint_url' | 'assume_role_arn'> {
116+
endpoint_url?: string | null
117+
assume_role_arn?: string | null
118+
}
119+
110120
export interface VaultPayload {
111121
name: VaultProviders
112122
prefix: string
113123
description: string | null
114124
tags: string[],
115-
config: KongVaultConfig | AWSVaultConfig | GCPVaultConfig | HCVVaultConfigPayload | AzureVaultConfigPayload
125+
config: KongVaultConfig | GCPVaultConfig | HCVVaultConfigPayload | AzureVaultConfigPayload | AWSVaultConfigPayload
116126
}
117127

118128
export interface VaultStateFields {

0 commit comments

Comments
 (0)