OpenShift Secrets Concepts: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(23 intermediate revisions by the same user not shown)
Line 14: Line 14:




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 to the pod. This approach is convenient when dealing with confidential data that we don't want stored in the images the pods are created from.  
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}}
For more details on the "Secret" primitive definition see: {{Internal|OpenShift Secret Definition|Secret Definition}}
Line 20: Line 20:
OpenShift uses secrets routinely to hold keys for authentication to other internal systems like Docker registries.
OpenShift uses secrets routinely to hold keys for authentication to other internal systems like Docker registries.


The simplest procedure to expose such name/value pair is:
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.


1. Create the secret, based on the content of a file
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.


echo "passwd123" > ./db-passwd
=An Example=


oc secret new  db-password-secret ./db-passwd
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.  


This is a terse syntax, where the name of the key is inferred from the name of the file. More explanatory syntax variants are available. TODO - link to operations.
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:


The secret thus created is:
echo "passwd123" > ./db-passwd


oc secret new db-password-secret ./db-passwd


oc get -o yaml secret/db-password-secret
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]].


apiVersion: v1
The secret thus created (secret/db-password-secret) is represented as:
data:
  db-passwd: cGFzc3dkMTIzCg==
kind: Secret


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


2. Expose the name/confidential value to a pod, automatically, 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 an environment variable.
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:


2.1 Exposing the data as a file, by using the volume mechanism:
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":


oc set volume dc/centos-loop --add --name=db-password-volume --mount-path=/etc/secrets --secret-name= db-password-secret
tmpfs on /etc/secrets type tmpfs (rw,relatime,seclabel)


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


The confidential data will become available to the pod as the content of the /etc/secrets/db-password file.
cat /etc/secrets/db-passwd
passwd123


The volume is mounted as "tmpfs":
More details on volume operations are available here: {{Internal|Oc_set#volumes|oc set volumes}}


mount
This is how the secret data is exposed as an environment variable.
tmpfs on /etc/secrets type tmpfs (rw,relatime,seclabel)


2.2 Exposing the data as the value of an environment variable:
[[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=


oc env dc/centos-loop --from=secret/db-password-secret --prefix=BLUE_
==Key File-Based==


env | grep BLUE
==Basic Auth==
BLUE_DB_PASSWD=passwd123


Difference from a ConfigMap.
A secret containing the user name and the password to use in [[Basic and Digest HTTP Authentication|HTTP basic authentication]].


Accessibility: not encrypted, base64 - how can it be protected?
{{Internal|OpenShift_Security_Operations#Basic_Authentication|Basic Auth Secret Creation and Usage}}
 
=Operations=


{{Internal|OpenShift_Security_Operations#.27Secret.27_Operations|Secret Operations}}
==SSH Auth==


=Organizatorium=
==Dockercfg==


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.
==Service Account Token==


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.
=Operations=


{{Internal|OpenShift_Secrets_Operations#Overview|Secret Operations}}


=Organizatorium=


==Secret Types==
* Difference from a ConfigMap.
 
* Accessibility: not encrypted, base64 - how can it be protected?
===Key File-Based===
 
===Basic Auth===
 
A secret containing the user name and the password to use in [[Basic and Digest HTTP Authentication|HTTP basic authentication]].
 
{{Internal|OpenShift_Security_Operations#Basic_Authentication|Basic Auth Secret Creation and Usage}}
 
===SSH Auth===
 
===Dockercfg===
 
===Service Account Token===

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?