Skip to content

Temporary User Access

Overview

At checkout, the broker creates a temporary MySQL user with ALL privileges on the target database. At checkin, the user is dropped. This pattern grants full database-level access for admin or DBA sessions — use it only when scoped role access is insufficient.

Before You Begin

  • The broker is running and connected (see Getting Started)
  • mysql client, aws CLI, and jq are installed on the broker host
  • The broker service account has CREATE USER, GRANT ALL, and DROP USER privileges

Checkout Routine

Full script: Aurora MySQL/permissions/temp-user/

Environment variables:

VariableNotes
userInjected — requesting user’s email
hostAurora cluster endpoint
dburlSame as host
secretAWS Secrets Manager secret name or ARN

Create temp user with ALL privileges:

DB_USER=$(echo "$user" | cut -d'@' -f1 | tr -cd '[:alnum:]')
DB_PASSWORD=$(openssl rand -base64 16 | tr -d '=/+')

SECRET_JSON=$(aws secretsmanager get-secret-value --secret-id "$secret" --query SecretString --output text)
ADMIN_USER=$(echo "$SECRET_JSON" | jq -r '.username')
ADMIN_PASS=$(echo "$SECRET_JSON" | jq -r '.password')

mysql -h "$dburl" -u "$ADMIN_USER" -p"$ADMIN_PASS" <<EOF
CREATE USER IF NOT EXISTS '${DB_USER}'@'%' IDENTIFIED BY '${DB_PASSWORD}';
GRANT ALL PRIVILEGES ON systemdb.* TO '${DB_USER}'@'%';
FLUSH PRIVILEGES;
EOF

echo "username=${DB_USER}"
echo "password=${DB_PASSWORD}"
echo "host=${host}"

Checkin Routine

Full script: Aurora MySQL/permissions/temp-user/

DB_USER=$(echo "$user" | cut -d'@' -f1 | tr -cd '[:alnum:]')

SECRET_JSON=$(aws secretsmanager get-secret-value --secret-id "$secret" --query SecretString --output text)
ADMIN_USER=$(echo "$SECRET_JSON" | jq -r '.username')
ADMIN_PASS=$(echo "$SECRET_JSON" | jq -r '.password')

mysql -h "$dburl" -u "$ADMIN_USER" -p"$ADMIN_PASS" <<EOF
DROP USER IF EXISTS '${DB_USER}'@'%';
FLUSH PRIVILEGES;
EOF

echo "User ${DB_USER} dropped."

This pattern grants ALL PRIVILEGES on the target database — use for admin sessions only. For day-to-day developer or analyst access, use Role-Based Access to limit the privilege to what the user actually needs.


Configure in Britive

Create a response template

Go to Resource Manager → Response Templates → New Template. Add fields for username, password, and host.

Create a permission

Go to Resource Manager → Resource Type Permissions → New Permission. Set Language to Shell.

Paste the checkout and checkin routines. Declare variables:

VariableSystem definedNotes
userYesInjected automatically
hostNoSet per resource
dburlNoSet per resource
secretNoSet per resource

Under Response Templates, attach the template you created.

Create a profile

Go to Resource Manager → Profiles → New Profile. Set a short expiration (e.g. 2h). Under Associations, select the resource label(s). Under Permissions, add this permission.

Add a policy with approval

Under Policies, assign members and add an approval condition — this pattern grants full database access and should require manager or DBA team approval.


Verify

Check out the profile

Navigate to My Access → find the profile → Check Out. Credentials appear in the response.

Connect and verify access

mysql -h <host> -u <username> -p<password> systemdb
SELECT current_user();
SHOW GRANTS;
-- Expected: GRANT ALL PRIVILEGES ON systemdb.* TO 'username'@'%'

Check in

Return to My AccessCheck In.

Confirm the user is dropped

mysql -h <host> -u <username> -p<password> systemdb
# Expected: ERROR 1045 (28000): Access denied

Troubleshoot

SymptomCauseFix
GRANT ALL failedbritive_svc lacks GRANT OPTIONAdd WITH GRANT OPTION to the service account’s grants
User still exists after checkinActive connection held the sessionKill the session manually: KILL CONNECTION <id>;, then retry checkin
Access denied on Secrets ManagerIAM role missing permissionAttach secretsmanager:GetSecretValue to the broker instance profile
Last updated on