Skip to content
Kong Logo | Kong Docs Logo
search
  • Docs
    • Explore the API Specs
      View all API Specs View all API Specs View all API Specs arrow image
    • Documentation
      API Specs
      Kong Gateway
      Lightweight, fast, and flexible cloud-native API gateway
      Kong Konnect
      Single platform for SaaS end-to-end connectivity
      Kong Mesh
      Enterprise service mesh based on Kuma and Envoy
      decK
      Helps manage Kong’s configuration in a declarative fashion
      Kong Ingress Controller
      Works inside a Kubernetes cluster and configures Kong to proxy traffic
      Kong Gateway Operator
      Manage your Kong deployments on Kubernetes using YAML Manifests
      Insomnia
      Collaborative API development platform
      Kuma
      Open-source distributed control plane with a bundled Envoy Proxy integration
  • Plugin Hub
    • Explore the Plugin Hub
      View all plugins View all plugins View all plugins arrow image
    • Functionality View all View all arrow image
      View all plugins
      Authentication's icon
      Authentication
      Protect your services with an authentication layer
      Security's icon
      Security
      Protect your services with additional security layer
      Traffic Control's icon
      Traffic Control
      Manage, throttle and restrict inbound and outbound API traffic
      Serverless's icon
      Serverless
      Invoke serverless functions in combination with other plugins
      Analytics & Monitoring's icon
      Analytics & Monitoring
      Visualize, inspect and monitor APIs and microservices traffic
      Transformations's icon
      Transformations
      Transform request and responses on the fly on Kong
      Logging's icon
      Logging
      Log request and response data using the best transport for your infrastructure
  • Support
  • Community
  • Kong Academy
Get a Demo Start Free Trial
Kong Gateway
2.8.x
  • Home icon
  • Kong Gateway
  • Plan And Deploy
  • Security
  • Secrets Management
  • Get Started with Secrets Management
github-edit-pageEdit this page
report-issueReport an issue
  • Kong Gateway
  • Kong Konnect
  • Kong Mesh
  • Plugin Hub
  • decK
  • Kong Ingress Controller
  • Kong Gateway Operator
  • Insomnia
  • Kuma

  • Docs contribution guidelines
  • 3.5.x (latest)
  • 3.4.x
  • 3.3.x
  • 3.2.x
  • 3.1.x
  • 3.0.x
  • 2.8.x
  • 2.7.x
  • 2.6.x
  • Archive (pre-2.6)
enterprise-switcher-icon Switch to OSS
On this pageOn this page
  • Getting started
    • Define a reference
    • Using the reference
You are browsing documentation for an outdated version. See the latest documentation here.

Get Started with Secrets Management

This feature is currently in beta state and isn’t fully supported. APIs are subject to change.

Secrets are generally confidential values that should not appear in plain text in the application. There are several products that help you store, retrieve, and rotate these secrets securely. Kong Gateway offers a mechanism to set up references to these secrets which makes your Kong Gateway installation more secure.

Getting started

When running Kong Gateway in hybrid or DB-less mode, secrets management is only supported in Kong Gateway 2.8.1.3 or later.

The following example uses the most basic form of secrets management: storing secrets in environment variables. In this example, you will replace a plaintext password to your PostgreSQL database with a reference to an environment variable.

You can also store secrets in a secure vault backend. For a list of supported vault backend implementations, see the Backends Overview.

In this example we’ll replace our plaintext password to our PostgreSQL database with a reference. To do so, please define your environment variable and assign a secret value to it.

Define a reference

Define your environment variable and assign a secret value to it:

export MY_SECRET_POSTGRES_PASSWORD="opensesame"

Next, set up a reference to this environment variable so that Kong Gateway can find this secret. We use a Uniform Resource Locator (URL) format for this.

In this case, the reference would look like this:

{vault://env/my_secret_postgres_password}

Where:

  • vault is the scheme (protocol) that we use to indicate that this is a secret.
  • env is the name of the backend (Environment Variables), since we’re storing the secret in a ENV variable.
  • my_secret_postgres_password corresponds to the environment variable that you just defined.

Note that the reference is wrapped in curly braces.

Using the reference

You can specify configuration options using environment variables or by directly updating the kong.conf configuration file.

Environment variable

Set the KONG_PG_PASSWORD environment variable to the following, adjusting my-secret-postgres-password to your own password object name:

KONG_PG_PASSWORD={vault://env/my-secret-postgres-password}

Configuration file

The kong.conf file contains the property pg_password. Replace the original value with the following, adjusting my-secret-postgres-password to your own password object name:

pg_password={vault://env/my-secret-postgres-password}

Upon startup, Kong Gateway tries to detect and transparently resolve references.

For quick debugging or testing, you can use the CLI for vaults.

See the Advanced Usage documentation for more information on the configuration options for each vault backend.

Thank you for your feedback.
Was this page useful?
Too much on your plate? close cta icon
More features, less infrastructure with Kong Konnect. 1M requests per month for free.
Try it for Free
  • Kong
    Powering the API world

    Increase developer productivity, security, and performance at scale with the unified platform for API management, service mesh, and ingress controller.

    • Products
      • Kong Konnect
      • Kong Gateway Enterprise
      • Kong Gateway
      • Kong Mesh
      • Kong Ingress Controller
      • Kong Insomnia
      • Product Updates
      • Get Started
    • Documentation
      • Kong Konnect Docs
      • Kong Gateway Docs
      • Kong Gateway Enterprise Docs
      • Kong Mesh Docs
      • Kong Insomnia Docs
      • Kong Konnect Plugin Hub
    • Open Source
      • Kong Gateway
      • Kuma
      • Insomnia
      • Kong Community
    • Company
      • About Kong
      • Customers
      • Careers
      • Press
      • Events
      • Contact
  • Terms• Privacy• Trust and Compliance
© Kong Inc. 2023