Role-Based Access
Overview
At checkout, the broker creates a temporary MySQL user derived from the requesting user’s email and grants a specific privilege (e.g. SELECT) on a target table. At checkin, the privilege is revoked and the user is dropped. Admin credentials are retrieved from AWS Secrets Manager at runtime.
Use this pattern for scoped, least-privilege access — for example, a data analyst who needs read access to a specific table for a limited time.
Before You Begin
- The broker is running and connected (see Getting Started)
mysqlclient,awsCLI, andjqare installed on the broker host- The broker host has an IAM role with
secretsmanager:GetSecretValuepermission - The broker service account (
britive_svc) has been created in Aurora MySQL with the required permissions
Checkout Routine
Full script: Aurora MySQL/permissions/role-member/
Environment variables:
| Variable | Default | Notes |
|---|---|---|
user | — | Injected — requesting user’s email; username is derived by stripping domain and non-alphanumeric chars |
host | — | Aurora cluster endpoint |
dburl | — | Same as host — the cluster endpoint |
secret | — | AWS Secrets Manager secret name or ARN containing admin credentials |
table | — | Target table in database.table format (e.g. myapp.orders) |
role | SELECT | MySQL privilege to grant (e.g. SELECT, INSERT, SELECT,INSERT) |
Retrieve credentials and create user:
# Derive MySQL username from email
DB_USER=$(echo "$user" | cut -d'@' -f1 | tr -cd '[:alnum:]')
# Retrieve admin credentials from Secrets Manager
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')
# Generate a random password for the temp user
DB_PASSWORD=$(openssl rand -base64 16 | tr -d '=/+')
# Create temp user and grant privilege on the target table
mysql -h "$dburl" -u "$ADMIN_USER" -p"$ADMIN_PASS" <<EOF
CREATE USER IF NOT EXISTS '${DB_USER}'@'%' IDENTIFIED BY '${DB_PASSWORD}';
GRANT ${role} ON ${table} TO '${DB_USER}'@'%';
FLUSH PRIVILEGES;
EOF
echo "username=${DB_USER}"
echo "password=${DB_PASSWORD}"
echo "host=${host}"Checkin Routine
Full script: Aurora MySQL/permissions/role-member/
Revoke and drop the 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
REVOKE ALL PRIVILEGES ON ${table} FROM '${DB_USER}'@'%';
DROP USER IF EXISTS '${DB_USER}'@'%';
FLUSH PRIVILEGES;
EOF
echo "User ${DB_USER} revoked and dropped."DROP USER IF EXISTS makes checkin idempotent — if the user was already removed (e.g. manual cleanup), checkin completes without error.
Configure in Britive
Create a response template
Go to Resource Manager → Response Templates → New Template. Add fields for username, password, and host from the checkout output.
Create a permission
Go to Resource Manager → Resource Type Permissions → New Permission. Set Language to Shell.
Paste the checkout and checkin routines into the respective fields.
Declare variables:
| Variable | System defined | Notes |
|---|---|---|
user | Yes | Injected automatically |
host | No | Set per resource |
dburl | No | Set per resource |
secret | No | Set per resource |
table | No | Set on permission or profile |
role | No | e.g. SELECT |
Under Response Templates, attach the template you created.
Create a profile
Go to Resource Manager → Profiles → New Profile. Set an expiration (e.g. 4h). Under Associations, select the resource label(s) for the Aurora clusters. Under Permissions, add the permission above.
Add a policy
Under Policies, assign members and configure approval conditions.
Verify
Check out the profile
Navigate to My Access → find the profile → Check Out. The MySQL host, username, and password appear in the checkout response.
Connect and confirm access
mysql -h <returned-host> -u <returned-username> -p<returned-password>-- Confirm the user and privilege
SELECT current_user();
SHOW GRANTS;
-- Expected: GRANT SELECT ON myapp.orders TO 'username'@'%'Check in
Return to My Access → Check In.
Confirm access is revoked
mysql -h <host> -u <returned-username> -p<returned-password>
# Expected: ERROR 1045 (28000): Access deniedTroubleshoot
| Symptom | Cause | Fix |
|---|---|---|
ERROR 1045: Access denied during checkout | Service account lacks GRANT OPTION | Grant WITH GRANT OPTION to britive_svc on the managed table |
ERROR 1142: command denied on GRANT | Wrong privilege name | Use uppercase MySQL privilege names: SELECT, INSERT, UPDATE |
Unable to locate credentials | Broker IAM role missing Secrets Manager permission | Attach secretsmanager:GetSecretValue to the broker instance profile |
| User still exists after checkin | Checkin routine failed | Check broker logs; run DROP USER IF EXISTS 'username'@'%'; manually |
table variable not resolved | Variable not declared on the permission | Add table to the permission variable list |