Does your Splunk app integrate with a third-party service or API? If so, that service might require your app’s users to authenticate using a secret. You can securely store and retrieve secrets in an app using the capabilities of the Splunk platform.
Secrets consist of sensitive data, including passwords, credentials, and API keys, that an app requires to run. Secrets allow your app’s users to authenticate with an external service and to access that service’s resources and APIs in your app.
In the Splunk platform, secrets contain the following fields:
When you store a secret in a Splunk app, the Splunk platform encrypts the secret and stores this information in the passwords.conf file. Authorized users can then retrieve and use the secret for authentication.
To store a secret in an app, you first need to collect the associated name, password, and realm using a setup page. Then, call the storage/passwords endpoint to encrypt the secret and save this information in the passwords.conf file.
To retrieve a secret from the passwords.conf file, submit a GET request to the storage/passwords endpoint. This API call returns the clear text, encrypted, and masked forms of the password associated with a user's credentials.
This diagram shows the workflow for how to store and retrieve secrets in an app using the storage/passwords endpoint:
Note: Users require specific capabilities to store and retrieve secrets in an app. See Configure access control for secret storage.
You can call the storage/passwords REST API endpoint to manage secret storage using the following methods:
In this blog post, we’ll walk through an example that uses the Splunk SDK for JavaScript to store a secret and the Splunk Enterprise REST API to retrieve the secret.
To store a secret in a Splunk app, you need to collect the associated name, password, and realm from the user. You can use a setup page to capture this information the first time that a user runs the app.
This screenshot shows a setup page, from the Developer Tutorial app, that prompts the user to create a password to complete app setup.
Under the hood, the setup page code uses the Splunk SDK for JavaScript to post the user’s password to the storage/passwords REST API endpoint, as shown in the following code snippet.
This code contains the following methods:
When you store a secret in an app, the Splunk platform encrypts the secret and saves this information in the $SPLUNK_HOME/etc/apps/appname/local/passwords.conf file. The following screenshot shows the encrypted secret that we stored in the Developer Tutorial app.
To retrieve a secret in clear text, submit a GET request to the storage/passwords REST API endpoint.
In this example, we’ll retrieve the secret that we stored in the Developer Tutorial app through calling the storage/passwords endpoint using the Splunk REST API directly, as shown in the following image.
The API call response contains the clear text, encrypted, and masked forms of the secret we stored in the app, as shown in the following image.
Check out the following resources to learn more about secret storage:
The Splunk platform removes the barriers between data and action, empowering observability, IT and security teams to ensure their organizations are secure, resilient and innovative.
Founded in 2003, Splunk is a global company — with over 7,500 employees, Splunkers have received over 1,020 patents to date and availability in 21 regions around the world — and offers an open, extensible data platform that supports shared data across any environment so that all teams in an organization can get end-to-end visibility, with context, for every interaction and business process. Build a strong data foundation with Splunk.