Skip to content
Directory & LifecycleMarkdown

Sensitive attributes

Seal or hash a value at rest, keep it out of every read and every search, and let only a root administrator change the values that matter most.

AvailableAPI

Some of what you keep about a user should never come back out: a national ID, a recovery secret, a password. Mark the attribute, and the realm seals or hashes it at rest, leaves it out of every read and the audit trail, and refuses to filter or sort on it, so a search can’t be used to guess it.

  • Privilege: RealmOwner, or a privilege of your own over type definitions, to mark attributes. Only a root administrator can add, change or remove x-root-protected. See Who may do what.
  • Where: the API, with your session in $CVYUH_SESSION (see Call the API).
  • Mark before you store. Add the mark before the first value is written.

Each mark goes on the attribute’s definition in the type:

MarkWhat the realm does
"scope": "private"Stores it as written, never returns it, and leaves it out of the audit trail. A write that leaves it out keeps the stored value
"x-encrypt": { "key": "store/encryption" }Seals it at rest with the realm’s own storage key. Goes with "scope": "private", on a text attribute
"x-hash": { "algorithm": "bcrypt" }Stores a one-way hash, as the realm does for passwords. pbkdf2 is the other choice

Values marked this way can’t be filtered, sorted or searched.

x-encrypt is always written the same way: { "key": "store/encryption" }, the realm’s storage key. Write it exactly so. "x-encrypt": true isn’t understood and leaves the value unsealed, with no error; a different key is accepted when you save the type but isn’t the realm’s storage key, so don’t use one.

Sealed values follow key rotation. When the realm’s storage key is rotated, sealed values are sealed again under its latest version. See Encryption of stored data.

Root-protected values. "x-root-protected": ["write"] lets everyone read a value but only a root administrator change it; ["read", "write"] also hides it from everyone else. Only a root administrator can add, change or remove this mark.

Read the type, add the attribute with its mark, and save it back, as Attributes and validation describes. A national ID, sealed and never returned:

"nationalId": { "type": "string", "scope": "private",
"x-encrypt": { "key": "store/encryption" } }

Then write it like any other attribute:

Terminal window
curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/user/maya \
-H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
-H "Content-Type: application/json" \
-d '{ "nationalId": "<value>" }'

A read of Maya never shows it.

WhatDefault or limit
x-encryptOnly on a text attribute that is also "scope": "private"; key always store/encryption
x-hash algorithmsbcrypt (the default for passwords) or pbkdf2
Searching a marked valueNever: left out of filters, sort and free text
AnswerCodeWhat it meansWhat to do
400INVALID_REQUESTThe type’s marks don’t fit: x-encrypt on an attribute that isn’t text or isn’t private, or a key that doesn’t readPut x-encrypt on a private text attribute, with { "key": "store/encryption" }
403FORBIDDENA change to x-root-protected by anyone but a root administratorAsk a root administrator

The save of the type is recorded with its definition. Writes of a marked value are recorded like any change, with the value left out: the history shows that the attribute changed, never what it holds.

SymptomCauseFix
A value you meant to seal reads backThe attribute isn’t "scope": "private", or x-encrypt was written as trueFix the definition as above, then write the value again
A search on the attribute is refusedMarked values can’t be searched, by designSearch on another attribute
  • A replace keeps what it can’t see. A PUT that leaves out a private value keeps the stored one, since the writer was never shown it.
  • Hashing is one-way. A hashed value can never be read back, by anyone, administrators included.
  • Passwords are already protected. The shipped passwordHash is private and bcrypt-hashed.