Skip to main content

Database Access with Oracle

Teleport can provide secure access to Oracle via the Teleport Database Service. This allows for fine-grained access control through Teleport's RBAC.

In this guide, you will:

  1. Configure an Oracle with mutual TLS authentication.
  2. Join the Oracle database to your Teleport cluster.
  3. Connect to the Oracle database via the Teleport Database Service.

Teleport Database Access Self-hosted Oracle

Prerequisites

  • A running Teleport Enterprise cluster. For details on how to set this up, see the Enterprise Getting Started guide.

  • The Enterprise tctl admin tool and tsh client tool version >= 14.3.33. You can download these tools by visiting your Teleport account. You can verify the tools you have installed by running the following commands:

    $ tctl version
    # Teleport Enterprise v14.3.33 go1.21

    $ tsh version
    # Teleport v14.3.33 go1.21
  • Self-hosted Oracle server instance 18c or later.
  • The sqlcl Oracle client installed and added to your system's PATH environment variable or any GUI client that supports JDBC Oracle thin client.

Step 1/6. Create a Teleport token and user

The Database Service requires a valid join token to join your Teleport cluster. Run the following tctl command and save the token output in /tmp/token on the server that will run the Database Service:

$ tctl tokens add --type=db --format=text
abcd123-insecure-do-not-use-this
tip

To modify an existing user to provide access to the Database Service, see Database Access Access Controls

Create a local Teleport user with the built-in access and requester roles:

$ tctl users add \
--roles=access,requester \
--db-users=\* \
--db-names=\* \
alice
FlagDescription
--rolesList of roles to assign to the user. The builtin access role allows them to connect to any database server registered with Teleport.
--db-usersList of database usernames the user will be allowed to use when connecting to the databases. A wildcard allows any user.
--db-namesList of logical databases (aka schemas) the user will be allowed to connect to within a database server. A wildcard allows any database.
warning

Database names are only enforced for PostgreSQL and MongoDB databases.

For more detailed information about database access controls and how to restrict access see RBAC documentation.

Step 2/6. Create a certificate/key pair and Teleport Oracle Wallet

Teleport uses mutual TLS authentication with self-hosted databases. These databases must be configured with Teleport's certificate authority to be able to verify client certificates. They also need a certificate/key pair that Teleport can verify.

If you are using Teleport Cloud, your Teleport user must be allowed to impersonate the system role Db in order to be able to generate the database certificate.

Include the following allow rule in in your Teleport Cloud user's role:

allow:
impersonate:
users: ["Db"]
roles: ["Db"]

Follow the instructions below to generate TLS credentials for your database.

# Export Teleport's certificate authority and a generated certificate/key pair
# for host db.example.com with a 3-month validity period.
$ tctl auth sign --format=oracle --host=db.example.com --out=server --ttl=2190h

In this example, db.example.com is the hostname where the Teleport Database Service can reach the Oracle server.

TTL

We recommend using a shorter TTL, but keep mind that you'll need to update the database server certificate before it expires to not lose the ability to connect. Pick the TTL value that best fits your use-case.

If tctl finds the Orapki tool in your local environment, the tctl auth sign --format=oracle --host=db.example.com --out=server --ttl=2190h command will produce an Oracle Wallet and instructions how to configure the Oracle TCPS listener with Teleport Oracle Wallet. Otherwise the tctl auth sign --format=oracle command will produce a p12 certificate and instructions on how to create an Oracle Wallet on your Oracle Database instance.

warning

If copying these files to your Oracle server, ensure the cert file permissions are readable by the oracle user.

Step 3/6. Configure Oracle Database

In order to enable the Teleport Oracle integration you will need to configure the TCPS Oracle listener and use the Teleport Oracle Wallet created in the previous step.

Align your listener.ora Oracle configuration file and add the following entries:

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCPS)(HOST = 0.0.0.0)(PORT = 2484))
)
)

WALLET_LOCATION = (SOURCE = (METHOD = FILE)(METHOD_DATA = (DIRECTORY = /path/to/oracleWalletDir)))
SSL_CLIENT_AUTHENTICATION = TRUE

Additionally, you will need to extend your sqlnet.ora Oracle configuration:

WALLET_LOCATION = (SOURCE = (METHOD = FILE)(METHOD_DATA = (DIRECTORY = /path/to/oracleWalletDir)))
SSL_CLIENT_AUTHENTICATION = TRUE
SQLNET.AUTHENTICATION_SERVICES = (TCPS)
tip

You will need to reload Oracle Listener lsnrctl reload after updating the listener.ora configuration file.

Additionally, your Oracle Database user accounts must be configured to require a valid client certificate. If you're creating a new user:

CREATE USER alice IDENTIFIED EXTERNALLY AS 'CN=alice';
GRANT CREATE SESSION TO alice;

Step 4/6. Configure and Start the Database Service

Install and configure Teleport where you will run the Teleport Database Service:

Use the appropriate commands for your environment to install your package:

# Download Teleport's PGP public key
$ sudo curl https://apt.releases.teleport.dev/gpg \
-o /usr/share/keyrings/teleport-archive-keyring.asc
# Source variables about OS version
$ source /etc/os-release
# Add the Teleport APT repository for v14. You'll need to update this
# file for each major release of Teleport.
$ echo "deb [signed-by=/usr/share/keyrings/teleport-archive-keyring.asc] \
https://apt.releases.teleport.dev/${ID?} ${VERSION_CODENAME?} stable/v14" \
| sudo tee /etc/apt/sources.list.d/teleport.list > /dev/null

$ sudo apt-get update
$ sudo apt-get install teleport-ent

For FedRAMP/FIPS-compliant installations, install the teleport-ent-fips package instead:

$ sudo apt-get install teleport-ent-fips

On the host where you will run the Teleport Database Service, start Teleport with the appropriate configuration.

Note that a single Teleport process can run multiple different services, for example multiple Database Service agents as well as the SSH Service or Application Service. The step below will overwrite an existing configuration file, so if you're running multiple services add --output=stdout to print the config in your terminal, and manually adjust /etc/teleport.yaml.

Generate a configuration file at /etc/teleport.yaml for the Database Service:

$ sudo teleport db configure create \
-o file \
--token=/tmp/token \
--proxy=teleport.example.com:443 \
--name=oracle \
--protocol=oracle \
--uri=oracle.example.com:2484 \
--labels=env=dev

Configure the Teleport Database Service to start automatically when the host boots up by creating a systemd service for it. The instructions depend on how you installed the Teleport Database Service.

On the host where you will run the Teleport Database Service, enable and start Teleport:

$ sudo systemctl enable teleport
$ sudo systemctl start teleport

You can check the status of the Teleport Database Service with systemctl status teleport and view its logs with journalctl -fu teleport.

Tip

A single Teleport process can run multiple services, for example multiple Database Service instances as well as other services such the SSH Service or Application Service.

Step 5/6. (Optional) Configure Teleport to pull audit logs from Oracle Audit Trail

Teleport can pull audit logs from Oracle Audit Trail. In order to enable this feature, you will need to configure Oracle Audit Trail and create a dedicated Teleport user that will be used to fetch audit events from Oracle Audit Trail.

Create an internal Oracle teleport user that will fetch audit events from Oracle Audit Trail:

CREATE USER teleport IDENTIFIED EXTERNALLY AS 'CN=teleport';
GRANT CREATE SESSION TO teleport;
GRANT SELECT ON dba_audit_trail TO teleport;
GRANT SELECT ON V_$SESSION TO teleport;

Enable the table in Oracle Audit Trail:

ALTER system SET audit_trail=db,extended scope=spfile;

Restart your Oracle instance to propagate audit trail changes.

Enable Oracle auditing for the alice user:

AUDIT ALL STATEMENTS by alice BY access;

You must enable auditing for each Teleport user that will be used to connect to Oracle. Additionally you can create a different audit policy for each user.

Configure the Teleport Database Service to pull audit logs from Oracle Audit Trail:

db_service:
enabled: "yes"
databases:
- name: "oracle"
protocol: "oracle"
uri: oracle.example.com:2484"
oracle:
audit_user: "teleport"

Teleport doesn't clean up audit trail events from Oracle Audit Trail. Make sure to configure an Oracle Audit Trail cleanup policy to avoid running out of disk space.

Step 6/6. Connect

Once the Database Service has joined the cluster, log in to see the available databases:

$ tsh login --proxy=mytenant.teleport.sh --user=alice
$ tsh db ls
# Name Description Allowed Users Labels Connect
# ------ -------------- ------------- ------- -------
# oracle Oracle Example [*] env=dev

Connect to the database:

$ tsh db connect --db-user=alice --db-name=XE oracle
#
#
# SQLcl: Release 22.4 Production on Fri Mar 31 20:48:02 2023
#
# Copyright (c) 1982, 2023, Oracle. All rights reserved.
#
# Connected to:
# Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production
# Version 21.3.0.0.0
#
# SQL>

To log out of the database and remove credentials:

# Remove credentials for a particular database instance.
$ tsh db logout oracle
# Remove credentials for all database instances.
$ tsh db logout

Next steps

  • See the YAML configuration reference for updating dynamic resource matchers or static database definitions.