Skip to content

Commit 792f5b0

Browse files
Christopher Giroirtreysp
andauthored
doc: add cloud secrets docs (#4563)
Co-authored-by: Trey Spiller <treyspiller@gmail.com>
1 parent 9e07751 commit 792f5b0

2 files changed

Lines changed: 74 additions & 1 deletion

File tree

docs/cloud/features/scheduler/scheduler.md

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,77 @@ Tobiko Cloud automatically manages Python dependencies of your Python macros and
167167

168168
SQLMesh automatically infers which Python libraries are used by statically analyzing the code of your models and macros.
169169

170-
For fine-grained control, dependencies can be specified, pinned, or excluded using the `sqlmesh-requirements.lock` file. See the [Python library dependencies](../../../guides/configuration.md#python-library-dependencies) section in the SQLMesh configuration guide for more information.
170+
For fine-grained control, dependencies can be specified, pinned, or excluded using the `sqlmesh-requirements.lock` file. See the [Python library dependencies](../../../guides/configuration.md#python-library-dependencies) section in the SQLMesh configuration guide for more information.
171+
172+
## Secret Manager
173+
174+
Tobiko Cloud provides a secrets manager where you can define environment variables for your project's Python models.
175+
176+
These variables are most commonly used to provide sensitive information to Python models, such as API keys or other credentials.
177+
178+
Secret values are encrypted at rest and only available in the environment of your running Python models.
179+
180+
!!! note "Cloud Scheduler Only"
181+
182+
Secrets from the secret manager do not load into hybrid executors. They are only used for cloud scheduler executors.
183+
184+
Secret names have two restrictions - they must:
185+
186+
- Start with a letter or an underscore
187+
- Only include letters, numbers, and underscores (no spaces or other symbols)
188+
189+
Secret values have no limits or restrictions. We recommend base64 encoding any secrets that contain binary data.
190+
191+
### Defining secrets
192+
193+
Define a secret on the Secrets page, accessible via the Settings section in Tobiko Cloud's left side navigation bar.
194+
195+
The Secrets page has a single panel you use to create a new secret, edit the value of an existing secret, or remove an existing secret. You cannot view the value of any existing secret.
196+
197+
In this example, only one secret has been defined: `MY_SECRET`. Update its value by entering a new value in the Secret field and clicking the `Update` button, or delete it by clicking the `Remove` button.
198+
199+
![secrets_panel](./scheduler/secrets.png)
200+
201+
202+
### Python Model Example
203+
204+
This Python model demonstrates how to read the `MY_SECRET` secret from an environment variable.
205+
206+
!!! danger "Protecting Secrets"
207+
208+
Only read environment variables from inside a Python model's `execute` function definition (not in the global scope).
209+
210+
If the variable is read in the global scope, SQLMesh will load the value from *your local system* when it renders the Python model instead of loading it at runtime on our executors.
211+
212+
This could expose sensitive information or embed an incorrect local value in the rendered model.
213+
214+
```python linenums="1"
215+
import os
216+
import pandas as pd
217+
import typing as t
218+
from datetime import datetime
219+
220+
from sqlmesh import ExecutionContext, model
221+
222+
# DO NOT read environment variables here.
223+
# Only inside the `execute` function definition!
224+
225+
@model(
226+
"my_model.name",
227+
columns={
228+
"column_name": "int",
229+
},
230+
)
231+
def execute(
232+
context: ExecutionContext,
233+
start: datetime,
234+
end: datetime,
235+
execution_time: datetime,
236+
**kwargs: t.Any,
237+
) -> pd.DataFrame:
238+
239+
# Read a secret from the MY_SECRET environment variable
240+
my_secret = os.environ["MY_SECRET"]
241+
242+
...
243+
```
57.2 KB
Loading

0 commit comments

Comments
 (0)