Skip to Content
Services

Secrets

Create a Secret, bind it in a Function, read its values, and control which Functions can change its values.

This page lists the spec fields of Secret, each with its type, its limits and its description. The Platform page explains the concept, and the metadata of every kind is the same.

Secret

apiVersion: funcd.io/v1alpha1
kind: Secret
metadata:
  name: app-secret
  namespace: default
  resourceGroup: rg1
spec:
  data:
    API_KEY: czNjcjN0
    SHARED: ZnJvbS1zZWNyZXQ=
apiVersionkind
funcd.io/v1alpha1Secret

Secret.spec

FieldType and limitsDescription
datamap of string to stringThe Secret's values by key, each in base64. Each key is an environment-variable name: a letter or an underscore, then letters, digits and underscores; a key that starts with FUNCD_ never reaches a workload. Each value must be UTF-8 text with no NUL byte: a Function or a Lake that binds a Secret holding another value does not start.
ownerobject, Secret.spec.ownerThe one Function or Job that may write the Secret's keys through ctx.secret, in its namespace, named with its kind, besides the writers that a RolesAssignment names, such as the Secret Data Writer role. The owner writes only while it binds the Secret. With no owner, only those writers can write it. An apply of the Secret replaces its data, keys a workload wrote included.
typestring, one of Opaquefuncd does not read it.

Secret.spec.owner

FieldType and limitsDescription
kindstring, required, one of Function, Lake, JobThe workload's kind. A Function, a Lake and a Job may share a name, so the kind says which one it is; each field names the kinds it accepts.
namestring, required, a DNS-1123 labelThe workload's name, in the object's namespace.

Handler API

The methods a handler calls on its context's clients, in each language funcd ships a shim for.

ctx.secret

The Secrets that the function binds. get and list read their keys and values at each call, with no cache, so a changed Secret shows at the next read; a key that starts with FUNCD_ is never read: get returns undefined for it, and list leaves it out. put and del change one key of a bound Secret that the function may write, as the Secret's owner or through a writer role such as Secret Data Writer.

MethodWhat it does
get(key: string): Promise<string | undefined>The key's value, or undefined when no bound Secret holds the key, the key starts with FUNCD_, or a bound Secret does not exist. When two Secrets hold the key, the later one in spec.bindings.secret wins. Fails with the HTTP status 403 when a Policy forbids the function to read a bound Secret.
list(): Promise<string[]>The keys that the bound Secrets hold, sorted, except a key that starts with FUNCD_. Fails with the HTTP status 403 when a Policy forbids the function to read a bound Secret, and 404 when a bound Secret does not exist.
put(binding: string, key: string, value: string): Promise<void>Writes key in Secret binding, which the function binds and may write: its owner, or a principal a writer role names. Every function that binds it reads the value at its next read. Fails with the HTTP status 403 when the function does not bind the Secret or may not write it, 404 when the Secret does not exist, 400 when the key or the value breaks a Secret's rules, 413 when the request passes 1 MiB, and 409 when the Secret changed under each of 5 attempts to write it.
del(binding: string, key: string): Promise<void>Removes key from Secret binding, which the function binds and may write, as for put; a key that the Secret lacks is no error. Fails with the HTTP status 403 when the function does not bind the Secret or may not write it, 404 when the Secret does not exist, and 409 when the Secret changed under each of 5 attempts to write it.

Each method here that calls funcd can also fail with the status 500 and the problem type urn:funcd:problem:internal, when funcd meets an error that it did not expect; funcd logs its cause.

When funcd refuses a call, the method fails with an error that holds funcd's status and problem type. This table gives them for each method, with when each happens and what to do.

MethodStatusProblem typeWhenWhat to do
get400urn:funcd:problem:invalidA Secret's value is not UTF-8 text, or it holds a NUL byte.Store the value as UTF-8 text with no NUL byte, such as in base64.
get403urn:funcd:problem:forbiddenA Policy forbids the Function to read a Secret that it binds.Change or remove the Policy that forbids secret::read on the Secret.
list400urn:funcd:problem:invalidA Secret's value is not UTF-8 text, or it holds a NUL byte.Store the value as UTF-8 text with no NUL byte, such as in base64.
list403urn:funcd:problem:forbiddenA Policy forbids the Function to read a Secret that it binds.Change or remove the Policy that forbids secret::read on the Secret.
list404urn:funcd:problem:not-foundThe calling Function no longer exists, so it binds no Secret.Call from a Function that exists; a deleted Function's worker stops.
list404urn:funcd:problem:not-foundA Secret that the Function binds does not exist.Create the Secret, or remove it from the Function's spec.bindings.secret.
put400urn:funcd:problem:invalidThe body of the write is not {"value": "<text>"}, as when the value is not a string.Write the value as a string.
put400urn:funcd:problem:invalidA Secret's value is not UTF-8 text, or it holds a NUL byte.Store the value as UTF-8 text with no NUL byte, such as in base64.
put400urn:funcd:problem:invalidThe key is not an environment-variable name: a letter or an underscore, then letters, digits and underscores.Use such a key.
put403urn:funcd:problem:forbiddenThe Function's spec.bindings.secret does not list the Secret.Add the Secret to spec.bindings.secret, or write a Secret that the Function binds.
put403urn:funcd:problem:forbiddenThe Function does not own the Secret, no RolesAssignment makes it a writer, or a Policy forbids the write.Write from the Secret's owner, or grant the Function secret::write with a RolesAssignment, such as the Secret Data Writer role.
put404urn:funcd:problem:not-foundThe calling Function no longer exists, so it binds no Secret.Call from a Function that exists; a deleted Function's worker stops.
put404urn:funcd:problem:not-foundA Secret that the Function binds does not exist.Create the Secret, or remove it from the Function's spec.bindings.secret.
put409urn:funcd:problem:conflictThe Secret changed under each attempt to write it, as when other writes of it run at the same time.Retry the write.
put413urn:funcd:problem:payload-too-largeThe request's body is larger than the local API takes for the call.Send a smaller body.
del403urn:funcd:problem:forbiddenThe Function's spec.bindings.secret does not list the Secret.Add the Secret to spec.bindings.secret, or write a Secret that the Function binds.
del403urn:funcd:problem:forbiddenThe Function does not own the Secret, no RolesAssignment makes it a writer, or a Policy forbids the write.Write from the Secret's owner, or grant the Function secret::write with a RolesAssignment, such as the Secret Data Writer role.
del404urn:funcd:problem:not-foundThe calling Function no longer exists, so it binds no Secret.Call from a Function that exists; a deleted Function's worker stops.
del404urn:funcd:problem:not-foundA Secret that the Function binds does not exist.Create the Secret, or remove it from the Function's spec.bindings.secret.
del409urn:funcd:problem:conflictThe Secret changed under each attempt to write it, as when other writes of it run at the same time.Retry the write.

HTTP API

The table lists each described operation of these kinds, with its method and path. The operation's page in the API reference gives its parameters, its body, its authentication and every answer, with when it happens and what to do.

MethodPathOperation
GET/apis/funcd.io/v1alpha1/namespaces/{namespace}/secretsList the Secrets of a namespace
POST/apis/funcd.io/v1alpha1/namespaces/{namespace}/secretsCreate a Secret
GET/apis/funcd.io/v1alpha1/namespaces/{namespace}/secrets/{name}Read a Secret
PUT/apis/funcd.io/v1alpha1/namespaces/{namespace}/secrets/{name}Replace a Secret
DELETE/apis/funcd.io/v1alpha1/namespaces/{namespace}/secrets/{name}Delete a Secret

On this page