Credentials are login details or secret values used to authenticate and access a protected service. They might let a vendor sign in to a portal or an application connect to a database. section 11.5.1 section 11.7
Hardcoding credentials creates avoidable risks:
- Committing them to source control can expose them, even if they are later deleted. section 11.5.1
- Using an administrator account gives a compromised service more access than it needs. section 11.5.1
- Changing a hardcoded password requires rebuilding, retesting, and redeploying the application. section 11.5.1
Listing 11.2 Secure Runtime Retrieval Refactor
import boto3
import json
from botocore.exceptions import ClientError
def get_database_credentials():
secret_name = "prod/BillingDatabase/Credentials"
region_name = "us-east-1"
# 1. Connect to the highly secure Secrets Manager
session = boto3.session.Session()
client = session.client(
service_name='secretsmanager',
region_name=region_name
)
try:
# 2. Request the credentials at runtime
get_secret_value_response = client.get_secret_value(
SecretId=secret_name
)
except ClientError as e:
raise e #A
# 3. Parse the secure response
secret_string = get_secret_value_response['SecretString']
secret_dict = json.loads(secret_string)
# 4. Return the credentials to be used by the ORM/Database connection
return secret_dict['username'], secret_dict['password']
db_user, db_pass = get_database_credentials() #B
connect_to_database(db_user, db_pass)
The Python example keeps the secret itself out of application code: it requests credentials from AWS Secrets Manager at runtime using boto3. A short-lived, least-privilege IAM role lets the server make that request. section 11.5.1
A vendor login becomes a path inward
In the Target HVAC breach, attackers stole a vendor’s portal login credentials through phishing. They then moved from the billing network into the retail network, where they reached point-of-sale systems. section 11.7









