Skip to main content

ordinary_config/app/secrets/
mod.rs

1// Copyright (C) 2026 The Ordinary Authors.
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5use serde::{Deserialize, Serialize};
6
7/// Where Ordinary will look for the secret.
8#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
9#[cfg_attr(feature = "docs", derive(schemars::JsonSchema))]
10#[derive(Deserialize, Serialize, Debug, Clone)]
11pub enum SecretSource {
12    /// Name of the host provided environment variable/secret.
13    ///
14    /// `Env` secrets are available to every tenant for a given
15    /// API server (when running in "multi" mode).
16    ///
17    /// This is useful in scenarios where a provider running the API
18    /// server would like to expose convenient integrations with 3rd parties, for
19    /// which it only wants to maintain a single set of credentials.
20    ///
21    /// `Env` secrets are also useful when you're running a standalone
22    /// application and do not need a more complicated secrets management
23    /// paradigm.
24    Env,
25    /// Name of a stored secret.
26    ///
27    /// `Stored` secrets are application scoped, and can be set
28    /// through an API server on which the application runs.
29    ///
30    /// `Stored` secrets live in their own database and are only
31    /// accessible to components with permissions.
32    Stored,
33    // `Manager` mode allows you to select an external secrets
34    // manager, by setting a `Stored` secret with the external `Manager`'s
35    // token/password.
36    // todo: Manager
37}
38
39/// Where the secret is accessible from.
40#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
41#[cfg_attr(feature = "docs", derive(schemars::JsonSchema))]
42#[derive(Deserialize, Serialize, Debug, Clone)]
43pub enum SecretVisibility {
44    // `Functions` visibility level should only be set in cases
45    // where you're confident in the code that's being executed,
46    // or the secret is not shared between trusted/untrusted modules.
47    //
48    // Because `Function` visible secrets are passed into the module,
49    // they can be (intentionally OR unintentionally) leaked if
50    // included in what's returned by the module.
51    // todo: Functions,
52    Extensions,
53}
54
55/// Mechanism for leveraging secrets.
56#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
57#[cfg_attr(feature = "docs", derive(schemars::JsonSchema))]
58#[derive(Deserialize, Serialize, Debug, Clone)]
59pub struct Secret {
60    /// Name of the secret.
61    pub name: String,
62    /// Where to retrieve the secret from.
63    pub source: SecretSource,
64    /// Where the secret is to be used.
65    pub visibility: SecretVisibility,
66}