test(e2e): Add Admin UI test for OIDC auth method (#2638)
* test(e2e): Add managed group check in LDAP test * test(e2e): Add oidc test * CR: Suppress warning * CR: Use toHaveText
This commit is contained in:
1 parent
ed569306bb
commit
ca4aad0a2b
5 files changed
+530
-11
No files matched your search
@@ -50,3 +50,116 @@ export async function getVaultToken(boundaryPolicyName, secretPolicyName) {
|
||||
|
||||
return clientToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up vault oidc provider
|
||||
* @param {string} vaultAddr address of vault server
|
||||
* @param {string} userName name of user to create in OIDC server
|
||||
* @param {string} password password of user
|
||||
* @param {string} email email of user
|
||||
* @param {string} boundaryAddr address of boundary server for the redirect uri
|
||||
* @returns {Promise<object>} OIDC info
|
||||
*/
|
||||
export async function setupVaultOidc(
|
||||
vaultAddr,
|
||||
userName,
|
||||
password,
|
||||
email,
|
||||
boundaryAddr,
|
||||
) {
|
||||
const authPolicyName = 'auth-policy';
|
||||
|
||||
execSync(`vault auth enable userpass`);
|
||||
execSync(
|
||||
`vault policy write ${authPolicyName} ./admin/tests/fixtures/auth-policy.hcl`,
|
||||
);
|
||||
execSync(
|
||||
`vault write auth/userpass/users/${userName} password=${password} token_policies=${authPolicyName} token_ttl=1h`,
|
||||
);
|
||||
execSync(
|
||||
`vault write identity/entity name=${userName} metadata=email=${email} metadata=phone_number=123-456-7890 disabled=false`,
|
||||
);
|
||||
const entityId = execSync(
|
||||
`vault read -field=id identity/entity/name/${userName}`,
|
||||
)
|
||||
.toString()
|
||||
.trim();
|
||||
const groupName = 'engineering';
|
||||
execSync(
|
||||
`vault write identity/group name=${groupName} member_entity_ids=${entityId}`,
|
||||
);
|
||||
const groupId = execSync(
|
||||
`vault read -field=id identity/group/name/${groupName}`,
|
||||
)
|
||||
.toString()
|
||||
.trim();
|
||||
const authList = JSON.parse(
|
||||
execSync(`vault auth list -detailed -format json`),
|
||||
);
|
||||
const userpassAccessor = authList['userpass/'].accessor;
|
||||
execSync(
|
||||
`vault write identity/entity-alias name=${userName} canonical_id=${entityId} mount_accessor=${userpassAccessor}`,
|
||||
);
|
||||
const assignmentName = 'my-assignment';
|
||||
execSync(
|
||||
`vault write identity/oidc/assignment/${assignmentName} entity_ids=${entityId} group_ids=${groupId}`,
|
||||
);
|
||||
const keyName = 'my-key';
|
||||
execSync(
|
||||
`vault write identity/oidc/key/${keyName} allowed_client_ids=* verification_ttl=2h rotation_period=1h algorithm=RS256`,
|
||||
);
|
||||
const oidcClientName = 'boundary';
|
||||
execSync(
|
||||
`vault write identity/oidc/client/${oidcClientName}` +
|
||||
` redirect_uris=${boundaryAddr}/v1/auth-methods/oidc:authenticate:callback` +
|
||||
` assignments=${assignmentName}` +
|
||||
` key=${keyName}` +
|
||||
` id_token_ttl=30m` +
|
||||
` access_token_ttl=1h`,
|
||||
);
|
||||
const clientId = execSync(
|
||||
`vault read -field=client_id identity/oidc/client/${oidcClientName}`,
|
||||
)
|
||||
.toString()
|
||||
.trim();
|
||||
const userScopeTemplate = `
|
||||
{
|
||||
"username": {{identity.entity.name}},
|
||||
"email": {{identity.entity.metadata.email}},
|
||||
"phone_number": {{identity.entity.metadata.phone_number}}
|
||||
}`;
|
||||
const userScopeEncoded = Buffer.from(userScopeTemplate).toString('base64');
|
||||
execSync(`vault write identity/oidc/scope/user template=${userScopeEncoded}`);
|
||||
const groupScopeTemplate = `
|
||||
{
|
||||
"groups": {{identity.entity.groups.names}}
|
||||
}`;
|
||||
const groupScopeEncoded = Buffer.from(groupScopeTemplate).toString('base64');
|
||||
execSync(
|
||||
`vault write identity/oidc/scope/groups template=${groupScopeEncoded}`,
|
||||
);
|
||||
|
||||
const providerName = 'my-provider';
|
||||
execSync(
|
||||
`vault write identity/oidc/provider/${providerName} allowed_client_ids=${clientId} scopes_supported=groups,user issuer=${vaultAddr} &> /dev/null`,
|
||||
);
|
||||
|
||||
const oidcConfig = JSON.parse(
|
||||
execSync(
|
||||
`curl -s ${vaultAddr}/v1/identity/oidc/provider/${providerName}/.well-known/openid-configuration`,
|
||||
),
|
||||
);
|
||||
const issuer = oidcConfig.issuer;
|
||||
const clientSecret = execSync(
|
||||
`vault read -field=client_secret identity/oidc/client/${oidcClientName}`,
|
||||
)
|
||||
.toString()
|
||||
.trim();
|
||||
|
||||
return {
|
||||
issuer: issuer,
|
||||
clientId: clientId,
|
||||
clientSecret: clientSecret,
|
||||
authPolicyName: authPolicyName,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user