You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`sfenv`is an *experimental application*, a *minimum viable product* to allow declaratively define Snowflake database environments and generate SQL statements for it.
3
+
`sfenv`helps manage *Snowflake Environments* consisting of Snowflake objects and permissions.
4
4
5
-
`sfenv` reads a set of *rules* from a YAML (or a JSON) file and produces SQL statements. [RULES.md](./RULES.md) describes the structure of such a file. Also, refer to [sample.yaml](./sample.yaml) for an example of a rules file.
5
+
Snowflake objects and permission are declaratively defined in a YAML/JSON file (called *Rules File*). See [sample.yaml](./sample.yaml) for an example and [RULES.md](./RULES.md) for a detailed description of rules specification.
6
6
7
7
## Features
8
8
9
9
With `sfenv` utility,
10
10
11
-
1.**Manage** following database objects
11
+
1. A single rule file can be used to manage one or more *environments*
12
+
1. The following database objects are supported
12
13
- Databases
13
14
- Schemas
14
15
- Warehouses
15
16
- Shares
16
17
- Users
17
18
- Application IDs
18
19
- Access Roles that control fine-grained access to objects or resources
19
-
- Functional Roles build on *Access Roles* for the purpose of granting permissions to User IDs
20
-
1.**Manage** privileges by following Snowflakerecommended [best practices](https://community.snowflake.com/s/article/Snowflake-Security-Overview-and-Best-Practices)
21
-
- privileges are granted to *Access Roles*
20
+
- Functional Roles build on *Access Roles* to grant permissions to User IDs
21
+
1.*Privileges* can be defined as per Snowflake's [recommended best practices](https://community.snowflake.com/s/article/Snowflake-Security-Overview-and-Best-Practices)
22
+
- privileges are granted to *Access Roles* (access roles are database roles when they apply to database objects)
22
23
- *Access Roles* are granted to *Functional Roles*
23
24
- *Functional Roles* are granted to *User IDs*
24
-
1. generate incremental (delta) SQL statements for only the changes made since the last time. This greatly reduces the number of SQL statements generated and the time it takes to run them.
25
-
1.manage different permissions for different environments with one rules file.
25
+
1.When the Rules-file is controlled by git, it is possible to generate incremental (delta) SQL statements for only the changes made since the last time (see [Maintaining State](#maintaining-state) below)
26
+
1.Customize permissions for specific environments within one rules file.
-`<Rulesfile>`: A YAML file containing object and privileges definitions
36
+
-`<Rules-file>`: A YAML/JSON file containing object and privileges definitions
36
37
-`--env ENV`: An *environment* name, to derive object and role names (default: `DEV`)
37
38
-`--diff <Rules file>`: Optional, when specified, SQL statements are generated only for the differences between the specified file and main rules file.
38
-
-`--drop <all|non-local|none`: determine how `DROP` SQL statements are produced
39
-
-`all`: all `DROP` statements are produced as normal SQL statements
40
-
-`non-local`: `DROP` statements that may lead to data loss (dropping local databases and schemas, but not imported from Shares) are commented out
41
-
-`none`: all `DROP` statements are commented out
42
-
-`--only-future`: When generating permissions for objects at schema level, generate only `FUTURE` grants (skip `ALL` grants)
39
+
-`--drop <all|non-local|none`: determine how the `DROP` SQL statements are generated
40
+
- `all`: all `DROP` statements are produced as normal SQL statements
41
+
- `non-local`: `DROP` statements that may lead to data loss (includes local databases and schemas, but not the *shared* databases) are commented out
42
+
- `none`: all `DROP` statements are commented out
43
+
-`--only-future`: When generating permissions for objects at the schema level, generate only `FUTURE` grants, and skip `ALL` grants which can be expensive to run
43
44
44
45
## Maintaining State
45
46
@@ -56,13 +57,13 @@ Run the following command to register `sfenv` as a `difftool`.
Any time you modify the rules file, you can then use the following command to generate SQL statements to automatically process only the changes made since the previous commit
60
+
Any time you modify the rules file, you can then use the following command to generate SQL statements to process only the changes made since the previous commit automatically
60
61
61
62
```sh
62
63
git difftool -yt sfenv my-rules.yaml
63
64
```
64
65
65
66
# Known Limitations
66
-
1.Support for only a small subset of Snowflake objects. Notably, managing Databases, Schemas, Warehouses, Roles, and permissions (RBAC) is extensively supported.
67
-
1. Error reporting may be terse, especially for YAML or JSON parsing errors. If you aren't sure if the rules file is a valid YAML or JSON file, it might be easier first to locate and fix errors by using any of the freely available online services.
67
+
1.Does not support all available Snowflake objects. Specifically, managing Databases, Schemas, Warehouses, Roles, Users and permissions (RBAC) are fully supported.
68
+
1. Error reporting may be terse, especially for YAML or JSON parsing errors. If you aren't sure if the rules file is a valid YAML or JSON file, it might be easier first to locate and fix mistakes by using any of the freely available online services.
68
69
1. There is no validation of object parameters or privileges. Any unrecognized object parameters or privileges are used verbatim in the generated SQL.
Copy file name to clipboardExpand all lines: RULES.md
+72-52Lines changed: 72 additions & 52 deletions
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
# Rules File
2
2
3
-
Rules file is a `yaml` or `json` file that is used by `sfenv` utility to generate DDLs and DCLs. A rule file contains one YAML/JSON object with several attributes (*sections*) to allow fine-grained creation of objects, roles and permissions.
3
+
Rules file is a `yaml` or a `json` file that is used by `sfenv` utility to generate Snowflake DDLs and DCLs. A *rules-file* consists of a configuration to help derive names, object definitions for one more *object types* (called *sections*), roles and permissions.
4
4
5
-
Sections (or attributes of the top-level object), are documented below. Only the `config` section is required, any other section may be omitted if not needed.
5
+
All available *sections*are documented below. Only the `config` section is required, all other sections may be omitted when not required.
6
6
7
7
-**`config`**
8
8
-`imports`
@@ -12,18 +12,18 @@ Sections (or attributes of the top-level object), are documented below. Only the
12
12
-`users`
13
13
-`apps`
14
14
15
-
Although the syntax doesn't explicitly list, but all object and role definitions accept `tags` mapping object containig a*tag* and a *value*
15
+
Although object properties listed below don't explicitly include them, but all object and role definitions accept `tags`*mapping object* consisting of*tag-name* and a *tag-value*
16
16
17
17
## `config`
18
18
19
-
A YAML/JSON object that controls naming of various database objects such as databases, schemas, roles etc. This object must have all attributes listed in the following example:
19
+
A YAML/JSON object that controls naming of database objects. This section must list all attributes shown in the following example:
20
20
21
21
**Example**:
22
22
23
23
```yaml
24
24
config:
25
25
secadm: "RL_{env}_SECADMIN"
26
-
sysadm: "RL_{env}_SYSADMIN"
26
+
dbadm: "RL_{env}_SYSADMIN"
27
27
database: "{db}_{env}"
28
28
schema: "{sch}"
29
29
warehouse: "WH_{env}_{wh}"
@@ -35,11 +35,13 @@ config:
35
35
36
36
Notes:
37
37
38
-
- Value for each attribute is a template to derive corresponding database object nameby substituting placeholder (names enclosed in `{}`).
39
-
- A special placeholder, named `env`, lets one rule file to generate different sets of SQL statements corresponding to different environments.
38
+
- Each attribute in `config` is a *template* to derive corresponding object name. Names are derived by substituting *placeholders* (variables enclosed in `{}`).
39
+
- A special placeholder, named `env`, lets one rule file to generate different sets of SQL statements for different environments.
40
40
- Value for `env` is supplied at runtime whereas values for all other placeholder names are taken from other sections within the rules file.
41
-
- Access role names are derived using the placeholders of the resource they control.
42
-
- Generated DDLs and DCLs contain appropriate `use role ...` statements to set either `secadm` and `sysadm`, which are security and system admin roles respectively. `secadm` manages other roles and permissions, whereas `sysadm` owns all database resources in an environment.
41
+
- Access role names are derived using the placeholders of the resource type they control.
42
+
- Generated DDLs and DCLs will include appropriate `use role <secadm>|<dbadm>` statements.
43
+
- `<secadm>`is security administrator ID for an environment and controls permissions
44
+
- `<dbadm>`is resource owner and owns the created objects
43
45
44
46
## `imports`
45
47
@@ -56,7 +58,6 @@ imports:
56
58
- DBA
57
59
- DEVLOPER
58
60
```
59
-
### imported share
60
61
An imported share is a YAML/JSON object that has following attributes:
61
62
62
63
- **`provider`**: provider account name
@@ -107,7 +108,7 @@ A database is a YAML/JSON object that has following attributes:
107
108
- `transient`: `true`if this is a transient database
108
109
- `comment`: comment that'll be part of the generated DDL
109
110
- `schemas`: A YAML/JSON list containing one or more schema YAML/JSON objects
110
-
- `...`: Any other attributes are generated as part of the DDL
111
+
- `...`: Any other attributes are passed through and become part of the DDL
111
112
112
113
### schema
113
114
A schema is a YAML/JSON object that defines a database schema and has following attributes:
@@ -116,7 +117,7 @@ A schema is a YAML/JSON object that defines a database schema and has following
116
117
- `managed`: `true`if this is a managed schema
117
118
- `comment`: comment that'll be part of the generated DDL
118
119
- `acc_roles`: A YAML/JSON object containing access role definitions to create
119
-
- `...`: Any other attributes are generated as part of the DDL
120
+
- `...`: Any other attributes are passed through and become part of the DDL
120
121
121
122
## `warehouses`
122
123
@@ -125,35 +126,33 @@ A schema is a YAML/JSON object that defines a database schema and has following
125
126
**Example**
126
127
127
128
```yaml
128
-
LOAD: &wh_defaults
129
-
warehouse_size: SMALL
130
-
initially_suspended: true
131
-
auto_suspend: 300
132
-
auto_resume: true
133
-
acc_roles:
134
-
R:
135
-
warehouse: [usage]
136
-
RW:
137
-
role: [R]
138
-
warehouse: [operate]
139
-
RWC:
140
-
role: [RW]
141
-
warehouse: [monitor, modify]
142
-
143
-
ETL:
144
-
<<: *wh_defaults
145
-
warehouse_size: X-LARGE
129
+
warehouses:
130
+
LOAD: &wh_defaults
131
+
warehouse_size: SMALL
132
+
initially_suspended: true
133
+
auto_suspend: 300
134
+
auto_resume: true
135
+
acc_roles:
136
+
R:
137
+
warehouse: [usage]
138
+
RW:
139
+
role: [R]
140
+
warehouse: [operate]
141
+
RWC:
142
+
role: [RW]
143
+
warehouse: [monitor, modify]
144
+
ETL:
145
+
<<: *wh_defaults
146
+
warehouse_size: X-LARGE
146
147
```
147
148
148
-
### warehouse
149
-
150
149
A warehouse is a YAML/JSON object with following attributes:
151
150
- `comment`: comment that'll be part of the generated DDL
152
151
- `acc_roles`: A YAML/JSON object containing access role definitions to create
153
-
- `...`: Any other attributes are generated as part of the DDL
152
+
- `...`: Any other attributes are passed through and become part of the DDL
154
153
155
154
## access roles
156
-
An access role is created for either a schema or a warehouse. An access role is specified as a YAML/JSON object with access role name as key and attribute being another YAML/JSON object that encodes a list of permissions for each database object type.
155
+
An access role is created for each schema or a warehouse. An access role is specified as a YAML/JSON object with access role name as key and attribute being another YAML/JSON object that encodes a list of permissions for each database object type.
157
156
158
157
**Example**
159
158
@@ -168,35 +167,56 @@ RW:
168
167
table: [insert, update, truncate, delete]
169
168
```
170
169
170
+
The above example when specified for a schema will
171
+
- create two database roles, corresponding to `R` and `RW`
172
+
- each access role specifies object type and permissions mapping
173
+
- permissions are list of SQL privileges
174
+
171
175
## `roles`
172
-
A YAML/JSON object containing one or more *functional role* names and their definitions
176
+
A YAML/JSON object containing one or more *functional role* names and their properties
173
177
174
-
### functional role
178
+
### functional roles
175
179
176
180
A functional role has following attributes:
177
181
- `comment`: comment that'll be part of the generated DDL
178
-
- `acc_roles`: A YAML/JSON list containing *references* to a mix of schema or warehouse access roles
179
-
- `env_acc_roles`: Allows specifying access role references per environment
180
-
181
-
### access role reference
182
-
An access role reference is a YAML/JSON object that has one of the following set of attributes:
182
+
- `acc_roles`: A YAML/JSON list containing *references* to schema and/or warehouse access roles
183
+
- `env_acc_roles`: Allows overriding access roles for specific environments
183
184
184
-
**Option 1**
185
-
- `database`: database name
186
-
- `schema`: schema name
187
-
- `acc`: access role name
185
+
**Example**
188
186
189
-
**Option 2**
190
-
- `warehouse`: warehouse name
191
-
- `acc`: access role name
187
+
```yaml
188
+
roles:
189
+
DEVELOPER:
190
+
comment: Developers
191
+
acc_roles:
192
+
EDW.CUSTOMER: R
193
+
BI.CUSTOMER: R
194
+
LOAD: R
195
+
ETL: R
196
+
env_acc_roles:
197
+
DEV: &dev_permissions
198
+
EDW.CUSTOMER: RWC
199
+
BI.CUSTOMER: RWC
200
+
LOAD: RW
201
+
QA: *dev_permissions
202
+
```
192
203
193
204
## `users`
194
-
A YAML/JSON object containing one or more *user* names and their definitions
205
+
A YAML/JSON object that describes Snowflake user IDs
195
206
196
-
### user
197
-
A YAML/JSON object with following attributes:
207
+
**Example**
208
+
209
+
```yaml
210
+
users:
211
+
JDOE:
212
+
comment: John Doe
213
+
roles:
214
+
- DBA
215
+
- SYSINFO
216
+
```
217
+
A *user* is an object mapping of name and its properties. Valid properties
198
218
- `comment`: comment that'll be part of the generated DDL
199
219
- `roles`: A YAML/JSON list containing names of the functional roles to be assigned to this user ID
200
220
201
221
## `apps`
202
-
A YAML/JSON object, very similar to `users`, except the IDs are created per environment.
222
+
Similar to `users` above except application IDs are created and are specific to an environment.
0 commit comments