OpenShift Secrets Concepts: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(27 intermediate revisions by the same user not shown)
Line 13: Line 13:
=Overview=
=Overview=


=Operations=


=Organizatorium=
A secret is a piece of text or binary data, associated with a name. OpenShift offers a "Secret" primitive, that can be created and managed independently of any other primitives, then associated with a pod in such a way that the name/data is exposed, or "delivered" to the pod. This approach is convenient when dealing with confidential data that should not be stored in the images the pods are created from.
 
For more details on the "Secret" primitive definition see: {{Internal|OpenShift Secret Definition|Secret Definition}}
 
OpenShift uses secrets routinely to hold keys for authentication to other internal systems like Docker registries.
 
The secrets are stored in a base64-encoded format, and delivered to pods as content of volumes or environment variables. Secrets from builds can also be referenced.
 
By default, every container is given a single secret which contains a token for accessing the API with limited privileges, at /var/run/secrets/kubernetes.io/serviceaccount.
 
=An Example=
 
A simple example of how to expose a name/value pair as a "secret" involves creation of the secret in the target project, then expose the secret to the pods created within the project by associating the secret with the deployment configuration that controls the pod creation.
 
One way to create a secret is to store the content into a file, and then use the file to create the secret via CLI:
 
echo "passwd123" > ./db-passwd
 
oc secret new db-password-secret ./db-passwd
 
This is a terse syntax, where the name of the key associated with the confidential data is inferred from file name. More flexible syntax variants [[OpenShift_Secrets_Operations#Create_a_Secret|are available]].
 
The secret thus created (secret/db-password-secret) is represented as:
 
apiVersion: v1
'''kind''': '''Secret'''
metadata:
  name: db-password-secret
  ...
type: Opaque
data:
  db-passwd: cGFzc3dkMTIzCg==
 
Once declared, the name/confidential value can be exposed to a pod, by associating the secret with the deployment configuration that creates the pod. The data can be exposed as a file, using the [[OpenShift_Concepts#Volume|volume mechanism]], or as an environment variable.
 
This is how the secret data is exposed as a volume, which is visible as a file to the processes running in pods:
 
oc set volume dc/<''deployment-config-name''> --add --name=db-password-volume --mount-path=/etc/secrets --secret-name=db-password-secret
 
After the pod gets redeployed as result of the configuration change, the volume is mounted as "tmpfs":
 
tmpfs on /etc/secrets type tmpfs (rw,relatime,seclabel)
 
The confidential data is available as the /etc/secrets/db-password file:
 
cat /etc/secrets/db-passwd
passwd123


A ''secret'' resource can hold text or binary secrets for delivery into pods. They are base64 encoded. Are mounted into pods using the volume mount mechanism. The volumes are backed by temporary file-storage facilities (tmpfs). Secrets from builds can be referenced.
More details on volume operations are available here: {{Internal|Oc_set#volumes|oc set volumes}}


By default, every container is given a single secret which contains a token for accessing the API with limited privileges, at /var/run/secrets/kubernetes.io/serviceaccount.  
This is how the secret data is exposed as an environment variable.


{{Internal|OpenShift_Security_Operations#.27Secret.27_Operations|Secret Operations}}
[[Oc_env#Set_a_Secret_as_Environment_Variable|oc env]] dc/<''deployment-config-name''> --from=secret/db-password-secret --prefix=BLUE_
env | grep BLUE
BLUE_DB_PASSWD=passwd123


==Secret Types==
=Secret Types=


===Key File-Based===
==Key File-Based==


===Basic Auth===
==Basic Auth==


A secret containing the user name and the password to use in [[Basic and Digest HTTP Authentication|HTTP basic authentication]].
A secret containing the user name and the password to use in [[Basic and Digest HTTP Authentication|HTTP basic authentication]].
Line 33: Line 81:
{{Internal|OpenShift_Security_Operations#Basic_Authentication|Basic Auth Secret Creation and Usage}}
{{Internal|OpenShift_Security_Operations#Basic_Authentication|Basic Auth Secret Creation and Usage}}


===SSH Auth===
==SSH Auth==


===Dockercfg===
==Dockercfg==
 
==Service Account Token==
 
=Operations=
 
{{Internal|OpenShift_Secrets_Operations#Overview|Secret Operations}}
 
=Organizatorium=


===Service Account Token===
* Difference from a ConfigMap.
* Accessibility: not encrypted, base64 - how can it be protected?

Latest revision as of 18:17, 30 January 2018

External

Internal

Overview

A secret is a piece of text or binary data, associated with a name. OpenShift offers a "Secret" primitive, that can be created and managed independently of any other primitives, then associated with a pod in such a way that the name/data is exposed, or "delivered" to the pod. This approach is convenient when dealing with confidential data that should not be stored in the images the pods are created from.

For more details on the "Secret" primitive definition see:

Secret Definition

OpenShift uses secrets routinely to hold keys for authentication to other internal systems like Docker registries.

The secrets are stored in a base64-encoded format, and delivered to pods as content of volumes or environment variables. Secrets from builds can also be referenced.

By default, every container is given a single secret which contains a token for accessing the API with limited privileges, at /var/run/secrets/kubernetes.io/serviceaccount.

An Example

A simple example of how to expose a name/value pair as a "secret" involves creation of the secret in the target project, then expose the secret to the pods created within the project by associating the secret with the deployment configuration that controls the pod creation.

One way to create a secret is to store the content into a file, and then use the file to create the secret via CLI:

echo "passwd123" > ./db-passwd
oc secret new db-password-secret ./db-passwd

This is a terse syntax, where the name of the key associated with the confidential data is inferred from file name. More flexible syntax variants are available.

The secret thus created (secret/db-password-secret) is represented as:

apiVersion: v1
kind: Secret
metadata:
  name: db-password-secret
  ...
type: Opaque
data:
  db-passwd: cGFzc3dkMTIzCg==

Once declared, the name/confidential value can be exposed to a pod, by associating the secret with the deployment configuration that creates the pod. The data can be exposed as a file, using the volume mechanism, or as an environment variable.

This is how the secret data is exposed as a volume, which is visible as a file to the processes running in pods:

oc set volume dc/<deployment-config-name> --add --name=db-password-volume --mount-path=/etc/secrets --secret-name=db-password-secret

After the pod gets redeployed as result of the configuration change, the volume is mounted as "tmpfs":

tmpfs on /etc/secrets type tmpfs (rw,relatime,seclabel)

The confidential data is available as the /etc/secrets/db-password file:

cat /etc/secrets/db-passwd
passwd123

More details on volume operations are available here:

oc set volumes

This is how the secret data is exposed as an environment variable.

oc env dc/<deployment-config-name> --from=secret/db-password-secret --prefix=BLUE_

env | grep BLUE
BLUE_DB_PASSWD=passwd123

Secret Types

Key File-Based

Basic Auth

A secret containing the user name and the password to use in HTTP basic authentication.

Basic Auth Secret Creation and Usage

SSH Auth

Dockercfg

Service Account Token

Operations

Secret Operations

Organizatorium

  • Difference from a ConfigMap.
  • Accessibility: not encrypted, base64 - how can it be protected?