Skip to content

Commit 949cf7d

Browse files
committed
Config credentials
1 parent 69b09d5 commit 949cf7d

File tree

14 files changed

+267
-0
lines changed

14 files changed

+267
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Credentials
2+
3+
A sample application demonstrating how configure user credentials in a YAML configuration.
4+
5+
## Running
6+
7+
Start the application by executing the following command in the [config](../../../config) directory:
8+
9+
```console
10+
$ tt start credentials
11+
```
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
credentials:
2+
users:
3+
admin:
4+
password: 'T0p_Secret_P@$$w0rd'
5+
replicator:
6+
password: 'topsecret'
7+
roles: [ replication ]
8+
storage:
9+
password: 'secret'
10+
roles: [ sharding ]
11+
sampleuser:
12+
password: '123456'
13+
roles: [ writers_space_reader ]
14+
privileges:
15+
- permissions: [ read, write ]
16+
spaces: [ books ]
17+
roles:
18+
writers_space_reader:
19+
privileges:
20+
- permissions: [ read ]
21+
spaces: [ writers ]
22+
23+
groups:
24+
group001:
25+
replicasets:
26+
replicaset001:
27+
instances:
28+
instance001:
29+
iproto:
30+
listen:
31+
- uri: '127.0.0.1:3301'
32+
33+
# Load sample data
34+
app:
35+
file: 'myapp.lua'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
instance001:
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function create_spaces()
2+
box.schema.space.create('writers')
3+
box.space.writers:format({
4+
{ name = 'id', type = 'unsigned' },
5+
{ name = 'name', type = 'string' }
6+
})
7+
box.space.writers:create_index('primary', { parts = { 'id' } })
8+
9+
box.schema.space.create('books')
10+
box.space.books:format({
11+
{ name = 'id', type = 'unsigned' },
12+
{ name = 'title', type = 'string' },
13+
{ name = 'author_id', foreign_key = { space = 'writers', field = 'id' } },
14+
})
15+
box.space.books:create_index('primary', { parts = { 'id' } })
16+
end
17+
18+
function load_data()
19+
box.space.writers:insert { 1, 'Leo Tolstoy' }
20+
box.space.writers:insert { 2, 'Fyodor Dostoevsky' }
21+
box.space.writers:insert { 3, 'Alexander Pushkin' }
22+
23+
box.space.books:insert { 1, 'War and Peace', 1 }
24+
box.space.books:insert { 2, 'Anna Karenina', 1 }
25+
box.space.books:insert { 3, 'Resurrection', 1 }
26+
box.space.books:insert { 4, 'Crime and Punishment', 2 }
27+
box.space.books:insert { 5, 'The Idiot', 2 }
28+
box.space.books:insert { 6, 'The Brothers Karamazov', 2 }
29+
box.space.books:insert { 7, 'Eugene Onegin', 3 }
30+
box.space.books:insert { 8, 'The Captain\'s Daughter', 3 }
31+
box.space.books:insert { 9, 'Boris Godunov', 3 }
32+
box.space.books:insert { 10, 'Ruslan and Ludmila', 3 }
33+
end
34+
35+
create_spaces()
36+
load_data()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Credentials: environment variables
2+
3+
A sample application demonstrating how set passwords in a YAML configuration using environment variables.
4+
5+
## Running
6+
7+
Before starting instances, set the `ADMIN_PASSWORD` and `REPLICATOR_PASSWORD` environment variables, for example:
8+
9+
```console
10+
$ export ADMIN_PASSWORD='T0p_Secret_P@$$w0rd'
11+
$ export REPLICATOR_PASSWORD='topsecret'
12+
```
13+
14+
Then, start the application by executing the following command in the [config](../../../config) directory:
15+
16+
```console
17+
$ tt start credentials_context_env
18+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
config:
2+
context:
3+
admin_password:
4+
from: env
5+
env: ADMIN_PASSWORD
6+
replicator_password:
7+
from: env
8+
env: REPLICATOR_PASSWORD
9+
10+
credentials:
11+
users:
12+
admin:
13+
password: '{{ context.admin_password }}'
14+
replicator:
15+
password: '{{ context.replicator_password }}'
16+
roles: [ replication ]
17+
18+
groups:
19+
group001:
20+
replicasets:
21+
replicaset001:
22+
instances:
23+
instance001:
24+
iproto:
25+
listen:
26+
- uri: '127.0.0.1:3301'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
instance001:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Credentials: files
2+
3+
A sample application demonstrating how load passwords to a YAML configuration from files.
4+
5+
## Running
6+
7+
Start the application by executing the following command in the [config](../../../config) directory:
8+
9+
```console
10+
$ tt start credentials_context_file
11+
```
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
config:
2+
context:
3+
admin_password:
4+
from: file
5+
file: secrets/admin_password.txt
6+
rstrip: true
7+
replicator_password:
8+
from: file
9+
file: secrets/replicator_password.txt
10+
rstrip: true
11+
12+
credentials:
13+
users:
14+
admin:
15+
password: '{{ context.admin_password }}'
16+
replicator:
17+
password: '{{ context.replicator_password }}'
18+
roles: [ replication ]
19+
20+
groups:
21+
group001:
22+
replicasets:
23+
replicaset001:
24+
instances:
25+
instance001:
26+
iproto:
27+
listen:
28+
- uri: '127.0.0.1:3301'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
instance001:

0 commit comments

Comments
 (0)