Secure Coding, Secrets & Logging
Quick Reference
Python for IT Automation | September -2027 Edition
Purpose Fast lookup for secure implementation, CI/CD configuration, diagnostic logging, and evidence review
Format Control tables, safe Python patterns, GitLab variable rules, troubleshooting cards, and final checklists
Use with Your current course directions, supplied lab values, repository, tests, rubric, and evaluator feedback
Core rule Validate input, minimize privilege, keep secrets out of code and output, log decisions without exposing data
Alignment boundary: This independently created reference supports D522 learning and review. It is not an official WGU publication,
rubric, answer file, or completed assessment. Course tasks and environments can change. Always use the exact current instructions,
filenames, endpoints, branches, credentials, evidence requirements, and permitted tools supplied in your course.
Academic-integrity boundary: Use the patterns to understand and verify your own implementation. Do not submit generic examples
as your work or expose real course credentials, personal data, or infrastructure details.
,WGU D522 | SECURE CODING, SECRETS & LOGGING QUICK REFERENCE
1. One-Page Security Decision Map
Use this sequence whenever data, credentials, remote systems, logs, or pipeline jobs are involved.
Step Decision Safe action Proof to retain
1. What data/system is Name the asset, trust boundary, and permitted operation. Requirement or configuration source
Identify touched?
2. Valid Can input be Allowlist format, type, range, length, and required fields. Positive + negative test
ate malformed or
hostile?
3. Auth Should this identity Use least privilege; separate authentication from Permission result without secret
orize perform the action? authorization.
4. Is any value Keep it out of source, YAML, screenshots, logs, Variable name/presence only
Protect sensitive? exceptions, and artifacts.
5. Exec Can the action hang Use timeouts, bounded retries, idempotence, and state Result + explicit status
ute or partially succeed? checks.
6. Did the intended live Read live state again; compare expected vs observed. Post-action verification
Verify state actually
change?
7. What will help Log event, target identifier, run ID, stage, outcome, and Correlated log lines
Record explain the outcome? safe error class.
8. Could evidence Crop minimally, redact safely, and confirm Evidence checklist
Review expose data? repository/history cleanliness.
Stop conditions
Stop rather than guess when an endpoint, approved baseline, credential source, destructive action, rollback rule, or target identity is
ambiguous. A visible output is not proof of correctness unless it comes from the intended input, current revision, and verified live
state.
Minimum secure outcome
Question Minimum acceptable answer
What happened? A stable event name and outcome
To what? A non-secret target/device identifier
When/which run? UTC timestamp and run/correlation ID
Was it verified? Expected and safe observed state, or a clear failure class
Can it be repeated safely? Defined idempotence, duplicate-prevention, or reconciliation behavior
Independent study resource | Page 2
, WGU D522 | SECURE CODING, SECRETS & LOGGING QUICK REFERENCE
2. Secure Coding Control Matrix
Risk Required control Python-oriented pattern Avoid
Untrusted input Allowlist + bounds + schema Parse once; reject wrong type/range/shape Trusting extension, UI, or
source
Command No shell interpolation Use argument lists with shell=False String-built commands;
execution shell=True
Path traversal Resolve beneath approved Compare resolved path parents Joining raw ../ input
root
Network call Timeout + status/schema Catch specific transport errors Unlimited wait; success by
check status alone
Mutation Preserve state + verify + Fresh read after write Assuming command exit
recover means fixed
Credentials External store + least Read required environment/CI variable Hard-coded token or password
privilege
Error handling Specific exceptions + safe Translate with raise ... from exc Silent catch or raw exception to
context user
Logging Allowlisted context + Parameterized messages Headers, payloads, env dumps
correlation
Dependencies Pin/review/scan Reproducible requirements Unreviewed latest versions
Non-negotiable invariants
[] No secret appears in tracked source, .gitlab-ci.yml, sample output, test fixture, screenshot, artifact, or log.
[] Every external operation has an explicit timeout and a defined failure classification.
[] A success message is emitted only after the success condition is independently verified.
[] User-controlled values never become executable shell syntax.
[] Tests cover expected input, malformed input, boundary values, exceptions, and regression behavior.
Independent study resource | Page 3