Sub topic 14
Handling Oracle Credentials Safely
Assume you can use SQL and a terminal, and that you understand the basic parts of an Oracle connection. This chapter focuses on protecting passwords, saved connections, wallets, and automated jobs.
A database connection has two separate kinds of information:
- Connection details identify the database. They include the host, port, and service name.
- Credentials prove who you are. They usually include a username and password, or another authentication method.
Connection details are often safe to share with your team. Credentials are secrets and need stronger protection.
Keep passwords out of commands
Do not put a password directly in an Easy Connect string:
sql hr/SecretPassword@//dbhost.example.com:1521/orclpdb1.example.comThe password can remain in shell history, terminal logs, CI logs, or the operating system's process list. Instead, start SQLcl without a connection and let it prompt for the password:
sql /nolog
SQL> connect hr@//dbhost.example.com:1521/orclpdb1.example.com
Password? (**********?) ********
Connected.The password is entered interactively and is not part of the command displayed at the prompt.
Protect saved SQLcl connections
SQLcl can save a connection under a name:
SQL> connect -save orclpdb_hr -savepwd hr@//dbhost.example.com:1521/orclpdb1.example.com
SQL> connmgr list
SQL> connect -name orclpdb_hrThis avoids repeatedly typing connection details. The -savepwd option also saves password information in SQLcl's local connection store. Use it only on a personal, access-controlled machine.
Do not use saved passwords when:
- The computer is shared.
- Several administrators use the same operating-system account.
- The connection store is copied into a container image or backup without protection.
- A team needs a shared connection. Each person should use an individual database account instead.
If you save a connection, protect the operating-system account and restrict access to SQLcl's configuration files. Remove saved connections when they are no longer needed.
Protect wallets
A cloud database wallet contains sensitive client connection material. Store the wallet outside source-control repositories and restrict its file permissions. Do not email it as an ordinary attachment or place it in a publicly readable directory.
For SQLcl, a wallet downloaded from Autonomous Database can be selected with:
SQL> set cloudconfig /secure/oracle/Wallet_MYDB.zip
SQL> connect admin@mydb_highUse a database account with only the privileges required by the task. Avoid using ADMIN for routine application work. Keep separate wallets and accounts for development, testing, and production.
Use safer automation
A script should contain connection details but not a password:
sql -S -L hr@orclpdb @report.sqlThe -S option enables silent mode, and -L limits the login attempt to one try. In automation, provide the credential through the CI system's protected secret facility or an approved operating-system secret store. Prevent the job from echoing commands and redact secrets from logs.
Do not use a powerful account such as SYSDBA in routine scripts. Privileged connections can change or remove database-wide objects, so use them only for a specific administrative task and keep them out of reusable application code.
Exercise
Why is sql hr/SecretPassword@//host:1521/service unsafe, and what should replace it for an interactive session?
Show answer
The password can appear in shell history, process listings, or logs. Start SQLcl with sql /nolog, then run connect hr@//host:1521/service so SQLcl prompts for the password.