Compare commits
624 Commits
version/20
...
version/20
Author | SHA1 | Date | |
---|---|---|---|
fedb81571d | |||
37528e1bba | |||
97ef2a6f5f | |||
cc1509cf57 | |||
0dfecc6ae2 | |||
c1e4d78672 | |||
0ab427b5bb | |||
a9f095d1d9 | |||
de17207c68 | |||
d9675695fe | |||
ec7f372fa9 | |||
8a675152e6 | |||
228fe01f92 | |||
b9547ece49 | |||
6e9bc143bd | |||
8cd4bf1be8 | |||
76660e4666 | |||
73b2e2cb82 | |||
d741d6dcf1 | |||
2575fa6db7 | |||
7512c57a2e | |||
e6e2dfd757 | |||
920d1f1b0e | |||
680d4fc20d | |||
4d3b25ea66 | |||
5106c0d0c1 | |||
fd09ade054 | |||
01629fe9e3 | |||
5be97e98e4 | |||
b1fd801ceb | |||
62a939b91d | |||
257ac04be4 | |||
ec5e6c14a2 | |||
1e1d9f1bdd | |||
da1ea51dad | |||
6ee3b8d644 | |||
6155c69b7c | |||
136d40d919 | |||
bb1bb9e22a | |||
05e84b63a2 | |||
7ab55f7afa | |||
f5ec5245c5 | |||
4f4f954693 | |||
c57fbcfd89 | |||
025fc3fe96 | |||
4d079522c4 | |||
08acc7ba41 | |||
7bdd32506e | |||
6283fedcd9 | |||
7a0badc81b | |||
1e134aa446 | |||
27bc5489c5 | |||
2dca45917c | |||
66a4338b48 | |||
a4dfc7e068 | |||
f98a9bed9f | |||
5d1bf4a0af | |||
34635ab928 | |||
fabe1130c1 | |||
8feda9c2b1 | |||
074928cac1 | |||
2308f90270 | |||
13adca0763 | |||
50ded723d1 | |||
e9064509fe | |||
6fdf3ad3e5 | |||
fb60cefb72 | |||
61f7db314a | |||
ef7952cab3 | |||
7e5d8624c8 | |||
2c54be85be | |||
2f8dbe9b97 | |||
cebe44403c | |||
7261017e13 | |||
0b3d33f428 | |||
6f0cbd5fa6 | |||
fb94aefd2f | |||
c4c8390eff | |||
8c2e4478fd | |||
94029ee612 | |||
8db49f9eca | |||
7bd25d90f4 | |||
133528ee90 | |||
578bd8fcb3 | |||
4c2ef95253 | |||
702a59222d | |||
48e2121a75 | |||
61249786ff | |||
008af4ccce | |||
02e3010efe | |||
aca4795e0c | |||
ff0febfecd | |||
4daad4b514 | |||
677bcaadd7 | |||
c6e9ecdd37 | |||
c9ecad6262 | |||
e545b3b401 | |||
fec96ea013 | |||
1ac1c50b67 | |||
d2f189c1d0 | |||
fb33906637 | |||
6d3a94f24f | |||
84f594e658 | |||
1486bd5ab2 | |||
2c00f4da2d | |||
c10a23220b | |||
f20243d545 | |||
903c6422ad | |||
f5ab955536 | |||
3a861f0497 | |||
744f250d05 | |||
83d435bd3b | |||
945cdfe212 | |||
fcc0963fab | |||
2ab4fcd757 | |||
bfe31b15ad | |||
49c4b43f32 | |||
19b1f3a8c1 | |||
80f218a6bf | |||
61aaa90226 | |||
7fdda5a387 | |||
94597fd2ad | |||
09808883f4 | |||
81ecb85a55 | |||
21bfaa3927 | |||
1c9c7be1c0 | |||
5a11dc567e | |||
4a1acd377b | |||
c5b84a91d1 | |||
e77ecda3b8 | |||
4e317c10c5 | |||
eb05a3ddb8 | |||
a22d6a0924 | |||
3f0d67779a | |||
0a937ae8e9 | |||
f8d94f3039 | |||
6bb261ac62 | |||
45f2c5bae7 | |||
5d8c1aa0b0 | |||
0101368369 | |||
4854f81592 | |||
4bed6e02e5 | |||
908f123d0e | |||
256dd24a1e | |||
d4284407f9 | |||
80da5dfc52 | |||
b6edf990e0 | |||
a66dcf9382 | |||
9095a840d5 | |||
72259f6479 | |||
0973c74b9d | |||
c7ed4f7ac1 | |||
3d577cf15e | |||
5474a32573 | |||
a5940b88e3 | |||
ff15716012 | |||
c040b13b29 | |||
4915e980c5 | |||
df362dd9ea | |||
d4e4f93cb4 | |||
3af0de6a00 | |||
4f24d61290 | |||
4c5c4dcf2c | |||
660b5cb6c6 | |||
6ff1ea73a9 | |||
3de224690a | |||
d4624b510a | |||
8856d762d0 | |||
5d1cbf14d1 | |||
6d5207f644 | |||
3b6497cd51 | |||
ff7320b0f8 | |||
e5a393c534 | |||
bb4be944dc | |||
21efee8f44 | |||
f61549a60f | |||
0a7bafd1b2 | |||
b3987c5fa0 | |||
0da043a9fe | |||
f336f204cb | |||
3bfcf18492 | |||
dfafe8b43d | |||
b5d43b15f8 | |||
2ccab75021 | |||
9070df6c26 | |||
a1c8ad55ad | |||
872c05c690 | |||
a9528dc1b5 | |||
0e59ade1f2 | |||
5ac49c695d | |||
3a30ecbe76 | |||
1f838bb2aa | |||
cc42830e23 | |||
593eb959ca | |||
5bb6785ad6 | |||
535c11a729 | |||
a0fa8d8524 | |||
c14025c579 | |||
8bc3db7c90 | |||
eaad564e23 | |||
511a94975b | |||
015810a2fd | |||
e70e6b84c2 | |||
d0b9c9a26f | |||
3e403fa348 | |||
48f4a971ef | |||
6314be14ad | |||
1a072c6c39 | |||
ef2eed0bdf | |||
91227b1e96 | |||
67d68629da | |||
e875db8f66 | |||
055a76393d | |||
0754821628 | |||
fca88d9896 | |||
dfe0404c51 | |||
fa61696b46 | |||
e5773738f4 | |||
cac8539d79 | |||
cf600f6f26 | |||
e194715c3e | |||
787f02d5dc | |||
a0ed01a610 | |||
02ba493759 | |||
a7fea5434d | |||
4fb783e953 | |||
affbf85699 | |||
0d92112a3f | |||
b1ad3ec9db | |||
c0601baca6 | |||
057c5c5e9a | |||
05429ab848 | |||
b66d51a699 | |||
f834bc0ff2 | |||
93fd883d7a | |||
7e080d4d68 | |||
3e3ca22d04 | |||
e741caa6b3 | |||
4343246a41 | |||
3f6f83b4b6 | |||
c63e1c9b87 | |||
f44cf06d22 | |||
3f609b8601 | |||
edd89b44a4 | |||
3e58748862 | |||
7088a6b0e6 | |||
6c880e0e62 | |||
cb1e70be7f | |||
6ba150f737 | |||
131769ea73 | |||
e68adbb30d | |||
f1eef09099 | |||
5ab3c7fa9f | |||
d0cec39a0f | |||
e15f53a39a | |||
25fb995663 | |||
eac658c64f | |||
15e2032493 | |||
c87f6cd9d9 | |||
e758995458 | |||
20c284a188 | |||
b0936ea8f3 | |||
bfc0f4a413 | |||
1a9a90cf6a | |||
00f1a6fa48 | |||
33754a06d2 | |||
69b838e1cf | |||
d5e04a2301 | |||
fbf251280f | |||
eaadf62f01 | |||
8c33e7a7c1 | |||
a7d9a80a28 | |||
2ea5dce8d3 | |||
14bf01efe4 | |||
67b24a60e4 | |||
e6775297cb | |||
4e4e2b36b6 | |||
3189c56fc3 | |||
5b5ea47b7a | |||
caa382f898 | |||
2d63488197 | |||
c1c8e4c8d4 | |||
a0e451c5e5 | |||
eaba8006e6 | |||
39ff202f8c | |||
654e0d6245 | |||
ec04443493 | |||
d247c262af | |||
dff49b2bef | |||
50666a76fb | |||
b51a7f9746 | |||
001dfd9f6c | |||
5e4fbeeb25 | |||
2c910bf6ca | |||
9b11319e81 | |||
40dc4b3fb8 | |||
0e37b98968 | |||
7e132eb014 | |||
49dfb4756e | |||
814758e2aa | |||
5c42dac5e2 | |||
88603fa4f7 | |||
0232c4e162 | |||
11753c1fe1 | |||
f5cc6c67ec | |||
8b8ed3527a | |||
1aa0274e7c | |||
ecd33ca0c1 | |||
e93be0de9a | |||
a5adc4f8ed | |||
a6baed9753 | |||
ceaf832e63 | |||
a6b0b14685 | |||
f679250edd | |||
acc4de2235 | |||
56a8276dbf | |||
6dfe6edbef | |||
6af4bd0d9a | |||
7ee7f6bd6a | |||
f8b8334010 | |||
d4b65dc4b4 | |||
e4bbd3b1c0 | |||
87de5e625d | |||
efbe51673e | |||
a95bea53ea | |||
6021fc0f52 | |||
1415b68ff4 | |||
be6853ac52 | |||
7fd6be5abb | |||
91d6f572a5 | |||
016a9ce34e | |||
8adb95af7f | |||
1dc54775d8 | |||
370ef716b5 | |||
16e56ad9ca | |||
b5b5a9eed3 | |||
8b22e7bcc3 | |||
d48b5b9511 | |||
0eccaa3f1e | |||
67d550a80d | |||
ebb5711c32 | |||
79ec872232 | |||
4284e14ff7 | |||
92a09779d0 | |||
14c621631d | |||
c55f503b9b | |||
a908cad976 | |||
c2586557d8 | |||
01c80a82e2 | |||
0d47654651 | |||
1183095833 | |||
c281b11bdc | |||
61fe45a58c | |||
d43aab479c | |||
7f8383427a | |||
a06d6cf33d | |||
5b7cb205c9 | |||
293a932d20 | |||
fff901ff03 | |||
f47c936295 | |||
88d5aec618 | |||
96ae68cf09 | |||
63b3434b6f | |||
947ecec02b | |||
1c2b452406 | |||
47777529ac | |||
949095c376 | |||
4b112c2799 | |||
291a2516b1 | |||
4dcfd021e2 | |||
ca50848db3 | |||
0bb3e3c558 | |||
e4b25809ab | |||
7bf932f8e2 | |||
99d04528b0 | |||
e48d172036 | |||
c2388137a8 | |||
650e2cbc38 | |||
b32800ea71 | |||
e1c0c0b20c | |||
fe39e39dcd | |||
883f213b03 | |||
538996f617 | |||
2f4c92deb9 | |||
ef335ec083 | |||
07b09df3fe | |||
e70e031a1f | |||
c7ba183dc0 | |||
3ed23a37ea | |||
3d724db0e3 | |||
2997542114 | |||
84b18fff96 | |||
1dce408c72 | |||
e5ff47bf14 | |||
b53bf331c3 | |||
90e9a8b34c | |||
845f842783 | |||
7397849c60 | |||
6dd46b5fc5 | |||
89ca79ed10 | |||
713bef895c | |||
925115e9ce | |||
42f5cf8c93 | |||
82cc1d536a | |||
08af2fd46b | |||
70e3b27a4d | |||
6a411d7960 | |||
33567b56d7 | |||
0c1954aeb7 | |||
f4a6c70e98 | |||
5f198e7fe4 | |||
d172d32817 | |||
af3fb5c2cd | |||
885efb526e | |||
3bfb8b2cb2 | |||
9fc5ff4b77 | |||
dd8b579dd6 | |||
e12cbd8711 | |||
62d35f8f8c | |||
49be504c13 | |||
edad55e51d | |||
38086fa8bb | |||
c4f9a3e9a7 | |||
930df791bd | |||
9a6086634c | |||
b68e65355a | |||
72d33a91dd | |||
7067e3d69a | |||
4db370d24e | |||
41e7b9b73f | |||
7f47f93e4e | |||
89abd44b76 | |||
14c7d8c4f4 | |||
525976a81b | |||
64a2126ea4 | |||
994c5882ab | |||
ad64d51e85 | |||
a184a7518a | |||
943fd80920 | |||
01bb18b8c4 | |||
94baaaa5a5 | |||
40b164ce94 | |||
1d7c7801e7 | |||
0db0a12ef3 | |||
8008aba450 | |||
eaeab27004 | |||
111fbf119b | |||
300ad88447 | |||
92cc0c9c64 | |||
18ff803370 | |||
819af78e2b | |||
6338785ce1 | |||
973e151dff | |||
fae6d83f27 | |||
ed84fe0b8d | |||
1ee603403e | |||
7db7b7cc4d | |||
68a98cd86c | |||
e758db5727 | |||
4d7d700afa | |||
f9a5add01d | |||
2986b56389 | |||
58f79b525d | |||
0a1c0dae05 | |||
e18ef8dab6 | |||
3cacc59bec | |||
4eea46d399 | |||
11e25617bd | |||
4817126811 | |||
0181361efa | |||
8ff8e1d5f7 | |||
19d5902a92 | |||
71dffb21a9 | |||
bd283c506d | |||
ef564e5f1a | |||
2543224c7c | |||
077eee9310 | |||
d894eeaa67 | |||
452bfb39bf | |||
6b6702521f | |||
c07b8d95d0 | |||
bf347730b3 | |||
ececfc3a30 | |||
b76546de0c | |||
424d490a60 | |||
127dd85214 | |||
10570ac7f8 | |||
dc5667b0b8 | |||
ec9cacb610 | |||
0027dbc0e5 | |||
c15e4b24a1 | |||
b6f518ffe6 | |||
4e476fd4e9 | |||
03503363e5 | |||
22d6621b02 | |||
0023df64c8 | |||
59a259e43a | |||
c6f39f5eb4 | |||
e3c0aad48a | |||
91dd33cee6 | |||
5a2c367e89 | |||
3b05c9cb1a | |||
6e53f1689d | |||
e3be0f2550 | |||
294f2243c1 | |||
7b1373e8d6 | |||
e70b486f20 | |||
b90174f153 | |||
7d7acd8494 | |||
4d9d7c5efb | |||
d614b3608d | |||
beb2715fa7 | |||
5769ff45b5 | |||
9d6f79558f | |||
41d5bff9d3 | |||
ec84ba9b6d | |||
042a62f99e | |||
907f02cfee | |||
53fe412bf9 | |||
ef9e177fe9 | |||
28e675596b | |||
9b7f57cc75 | |||
935a8f4d58 | |||
01fcbb325b | |||
7d3d17acb9 | |||
e434321f7c | |||
ebd476be14 | |||
31ba543c62 | |||
a101d48b5a | |||
4c166dcf52 | |||
47b1f025e1 | |||
8f44c792ac | |||
e57b6f2347 | |||
275d0dfd03 | |||
f18cbace7a | |||
212220554f | |||
a596392bc3 | |||
3e22740eac | |||
d18a691f63 | |||
3cd5e68bc1 | |||
c741c13132 | |||
924f6f104a | |||
454594025b | |||
e72097292c | |||
ab17a12184 | |||
776f3f69a5 | |||
8560c7150a | |||
301386fb4a | |||
68e8b6990b | |||
4f800c4758 | |||
90c31c2214 | |||
50e3d317b2 | |||
3eed7bb010 | |||
0ef8edc9f1 | |||
a6373ebb33 | |||
bf8ce55eea | |||
61b4fcb5f3 | |||
81275e3bd1 | |||
7988bf7748 | |||
00d8eec360 | |||
82150c8e84 | |||
1dbd749a74 | |||
a96479f16c | |||
5d5fb1f37e | |||
b6f4d6a5eb | |||
8ab5c04c2c | |||
386944117e | |||
9154b9b85d | |||
fc19372709 | |||
e5d9c6537c | |||
bf5cbac314 | |||
5cca637a3d | |||
5bfb8b454b | |||
4d96437972 | |||
d03b0b8152 | |||
c249b55ff5 | |||
1e1876b34c | |||
a27493ad1b | |||
95b1ab820e | |||
5cf9f0002b | |||
fc7a452b0c | |||
25ee0e4b45 | |||
46f12e62e8 | |||
4245dea25a | |||
908db3df81 | |||
ef4f9aa437 | |||
902dd83c67 | |||
1c4b78b5f4 | |||
d854d819d1 | |||
f246da6b73 | |||
4a56b5e827 | |||
53b10e64f8 | |||
27e4c7027c | |||
410d1b97cd | |||
f93f7e635b | |||
74eba04735 | |||
01bdaffe36 | |||
f6b556713a | |||
abe38bb16a | |||
f2b8d45999 | |||
3f61dff1cb | |||
b19da6d774 | |||
7c55616e29 | |||
952a7f07c1 | |||
6510b97c1e | |||
19b707a0fb | |||
320a600349 | |||
10110deae5 | |||
884c546f32 | |||
abec906677 | |||
22d1dd801c | |||
03891cbe09 | |||
3c5157dfd4 | |||
d241e8d51d | |||
7ba15884ed | |||
47356915b1 | |||
2520c92b78 | |||
e7e0e6d213 | |||
ca0250e19f | |||
cf4c7c1bcb | |||
670af8789a | |||
5c5634830f | |||
b6b0edb7ad | |||
45440abc80 |
@ -1,5 +1,5 @@
|
|||||||
[bumpversion]
|
[bumpversion]
|
||||||
current_version = 2021.12.4
|
current_version = 2022.3.1
|
||||||
tag = True
|
tag = True
|
||||||
commit = True
|
commit = True
|
||||||
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\-?(?P<release>.*)
|
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\-?(?P<release>.*)
|
||||||
@ -17,6 +17,8 @@ values =
|
|||||||
beta
|
beta
|
||||||
stable
|
stable
|
||||||
|
|
||||||
|
[bumpversion:file:pyproject.toml]
|
||||||
|
|
||||||
[bumpversion:file:docker-compose.yml]
|
[bumpversion:file:docker-compose.yml]
|
||||||
|
|
||||||
[bumpversion:file:schema.yml]
|
[bumpversion:file:schema.yml]
|
||||||
|
2
.github/stale.yml
vendored
2
.github/stale.yml
vendored
@ -7,7 +7,7 @@ exemptLabels:
|
|||||||
- pinned
|
- pinned
|
||||||
- security
|
- security
|
||||||
- pr_wanted
|
- pr_wanted
|
||||||
- enhancement/confirmed
|
- enhancement
|
||||||
# Comment to post when marking an issue as stale. Set to `false` to disable
|
# Comment to post when marking an issue as stale. Set to `false` to disable
|
||||||
markComment: >
|
markComment: >
|
||||||
This issue has been automatically marked as stale because it has not had
|
This issue has been automatically marked as stale because it has not had
|
||||||
|
145
.github/workflows/ci-main.yml
vendored
145
.github/workflows/ci-main.yml
vendored
@ -31,66 +31,57 @@ jobs:
|
|||||||
- pending-migrations
|
- pending-migrations
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v3
|
||||||
with:
|
- uses: actions/setup-node@v3.0.0
|
||||||
python-version: '3.9'
|
|
||||||
- uses: actions/setup-node@v2
|
|
||||||
with:
|
with:
|
||||||
node-version: '16'
|
node-version: '16'
|
||||||
- id: cache-pipenv
|
- id: cache-poetry
|
||||||
uses: actions/cache@v2.1.7
|
uses: actions/cache@v2.1.7
|
||||||
with:
|
with:
|
||||||
path: ~/.local/share/virtualenvs
|
path: ~/.cache/pypoetry/virtualenvs
|
||||||
key: ${{ runner.os }}-pipenv-v2-${{ hashFiles('**/Pipfile.lock') }}
|
key: ${{ runner.os }}-poetry-cache-v2-${{ hashFiles('**/poetry.lock') }}
|
||||||
- name: prepare
|
- name: prepare
|
||||||
env:
|
env:
|
||||||
INSTALL: ${{ steps.cache-pipenv.outputs.cache-hit }}
|
INSTALL: ${{ steps.cache-poetry.outputs.cache-hit }}
|
||||||
run: scripts/ci_prepare.sh
|
run: scripts/ci_prepare.sh
|
||||||
- name: run job
|
- name: run job
|
||||||
run: pipenv run make ci-${{ matrix.job }}
|
run: poetry run make ci-${{ matrix.job }}
|
||||||
test-migrations:
|
test-migrations:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v3
|
||||||
with:
|
- id: cache-poetry
|
||||||
python-version: '3.9'
|
|
||||||
- id: cache-pipenv
|
|
||||||
uses: actions/cache@v2.1.7
|
uses: actions/cache@v2.1.7
|
||||||
with:
|
with:
|
||||||
path: ~/.local/share/virtualenvs
|
path: ~/.cache/pypoetry/virtualenvs
|
||||||
key: ${{ runner.os }}-pipenv-v2-${{ hashFiles('**/Pipfile.lock') }}
|
key: ${{ runner.os }}-poetry-cache-v2-${{ hashFiles('**/poetry.lock') }}
|
||||||
- name: prepare
|
- name: prepare
|
||||||
env:
|
env:
|
||||||
INSTALL: ${{ steps.cache-pipenv.outputs.cache-hit }}
|
INSTALL: ${{ steps.cache-poetry.outputs.cache-hit }}
|
||||||
run: scripts/ci_prepare.sh
|
run: scripts/ci_prepare.sh
|
||||||
- name: run migrations
|
- name: run migrations
|
||||||
run: pipenv run python -m lifecycle.migrate
|
run: poetry run python -m lifecycle.migrate
|
||||||
test-migrations-from-stable:
|
test-migrations-from-stable:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v3
|
||||||
with:
|
|
||||||
python-version: '3.9'
|
|
||||||
- name: prepare variables
|
- name: prepare variables
|
||||||
id: ev
|
id: ev
|
||||||
run: |
|
run: |
|
||||||
python ./scripts/gh_env.py
|
python ./scripts/gh_env.py
|
||||||
- id: cache-pipenv
|
sudo pip install -U pipenv
|
||||||
|
- id: cache-poetry
|
||||||
uses: actions/cache@v2.1.7
|
uses: actions/cache@v2.1.7
|
||||||
with:
|
with:
|
||||||
path: ~/.local/share/virtualenvs
|
path: ~/.cache/pypoetry/virtualenvs
|
||||||
key: ${{ runner.os }}-pipenv-v2-${{ hashFiles('**/Pipfile.lock') }}
|
key: ${{ runner.os }}-poetry-cache-v2-${{ hashFiles('**/poetry.lock') }}
|
||||||
- name: checkout stable
|
- name: checkout stable
|
||||||
id: stable
|
|
||||||
run: |
|
run: |
|
||||||
# Save current branch
|
|
||||||
current=$(git branch --show)
|
|
||||||
echo ##[set-output name=originalBranch]$current
|
|
||||||
# Copy current, latest config to local
|
# Copy current, latest config to local
|
||||||
cp authentik/lib/default.yml local.env.yml
|
cp authentik/lib/default.yml local.env.yml
|
||||||
cp -R .github ..
|
cp -R .github ..
|
||||||
@ -100,49 +91,47 @@ jobs:
|
|||||||
mv ../.github ../scripts .
|
mv ../.github ../scripts .
|
||||||
- name: prepare
|
- name: prepare
|
||||||
env:
|
env:
|
||||||
INSTALL: ${{ steps.cache-pipenv.outputs.cache-hit }}
|
INSTALL: ${{ steps.cache-poetry.outputs.cache-hit }}
|
||||||
run: |
|
run: |
|
||||||
scripts/ci_prepare.sh
|
scripts/ci_prepare.sh
|
||||||
# Sync anyways since stable will have different dependencies
|
# install anyways since stable will have different dependencies
|
||||||
pipenv sync --dev
|
poetry install
|
||||||
- name: run migrations to stable
|
- name: run migrations to stable
|
||||||
run: pipenv run python -m lifecycle.migrate
|
run: poetry run python -m lifecycle.migrate
|
||||||
- name: checkout current code
|
- name: checkout current code
|
||||||
run: |
|
run: |
|
||||||
set -x
|
set -x
|
||||||
git fetch
|
git fetch
|
||||||
git reset --hard HEAD
|
git reset --hard HEAD
|
||||||
git checkout ${{ steps.stable.outputs.originalBranch }}
|
git checkout $GITHUB_SHA
|
||||||
pipenv sync --dev
|
poetry install
|
||||||
- name: prepare
|
- name: prepare
|
||||||
env:
|
env:
|
||||||
INSTALL: ${{ steps.cache-pipenv.outputs.cache-hit }}
|
INSTALL: ${{ steps.cache-poetry.outputs.cache-hit }}
|
||||||
run: scripts/ci_prepare.sh
|
run: scripts/ci_prepare.sh
|
||||||
- name: migrate to latest
|
- name: migrate to latest
|
||||||
run: pipenv run python -m lifecycle.migrate
|
run: poetry run python -m lifecycle.migrate
|
||||||
test-unittest:
|
test-unittest:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v3
|
||||||
with:
|
- id: cache-poetry
|
||||||
python-version: '3.9'
|
|
||||||
- id: cache-pipenv
|
|
||||||
uses: actions/cache@v2.1.7
|
uses: actions/cache@v2.1.7
|
||||||
with:
|
with:
|
||||||
path: ~/.local/share/virtualenvs
|
path: ~/.cache/pypoetry/virtualenvs
|
||||||
key: ${{ runner.os }}-pipenv-v2-${{ hashFiles('**/Pipfile.lock') }}
|
key: ${{ runner.os }}-poetry-cache-v2-${{ hashFiles('**/poetry.lock') }}
|
||||||
- name: prepare
|
- name: prepare
|
||||||
env:
|
env:
|
||||||
INSTALL: ${{ steps.cache-pipenv.outputs.cache-hit }}
|
INSTALL: ${{ steps.cache-poetry.outputs.cache-hit }}
|
||||||
run: scripts/ci_prepare.sh
|
run: scripts/ci_prepare.sh
|
||||||
- uses: testspace-com/setup-testspace@v1
|
- uses: testspace-com/setup-testspace@v1
|
||||||
with:
|
with:
|
||||||
domain: ${{github.repository_owner}}
|
domain: ${{github.repository_owner}}
|
||||||
- name: run unittest
|
- name: run unittest
|
||||||
run: |
|
run: |
|
||||||
pipenv run make test
|
poetry run make test
|
||||||
pipenv run coverage xml
|
poetry run coverage xml
|
||||||
- name: run testspace
|
- name: run testspace
|
||||||
if: ${{ always() }}
|
if: ${{ always() }}
|
||||||
run: |
|
run: |
|
||||||
@ -152,18 +141,16 @@ jobs:
|
|||||||
test-integration:
|
test-integration:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v3
|
||||||
with:
|
- id: cache-poetry
|
||||||
python-version: '3.9'
|
|
||||||
- id: cache-pipenv
|
|
||||||
uses: actions/cache@v2.1.7
|
uses: actions/cache@v2.1.7
|
||||||
with:
|
with:
|
||||||
path: ~/.local/share/virtualenvs
|
path: ~/.cache/pypoetry/virtualenvs
|
||||||
key: ${{ runner.os }}-pipenv-v2-${{ hashFiles('**/Pipfile.lock') }}
|
key: ${{ runner.os }}-poetry-cache-v2-${{ hashFiles('**/poetry.lock') }}
|
||||||
- name: prepare
|
- name: prepare
|
||||||
env:
|
env:
|
||||||
INSTALL: ${{ steps.cache-pipenv.outputs.cache-hit }}
|
INSTALL: ${{ steps.cache-poetry.outputs.cache-hit }}
|
||||||
run: scripts/ci_prepare.sh
|
run: scripts/ci_prepare.sh
|
||||||
- uses: testspace-com/setup-testspace@v1
|
- uses: testspace-com/setup-testspace@v1
|
||||||
with:
|
with:
|
||||||
@ -172,8 +159,8 @@ jobs:
|
|||||||
uses: helm/kind-action@v1.2.0
|
uses: helm/kind-action@v1.2.0
|
||||||
- name: run integration
|
- name: run integration
|
||||||
run: |
|
run: |
|
||||||
pipenv run make test-integration
|
poetry run make test-integration
|
||||||
pipenv run coverage xml
|
poetry run coverage xml
|
||||||
- name: run testspace
|
- name: run testspace
|
||||||
if: ${{ always() }}
|
if: ${{ always() }}
|
||||||
run: |
|
run: |
|
||||||
@ -183,11 +170,9 @@ jobs:
|
|||||||
test-e2e-provider:
|
test-e2e-provider:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v3
|
||||||
with:
|
- uses: actions/setup-node@v3.0.0
|
||||||
python-version: '3.9'
|
|
||||||
- uses: actions/setup-node@v2
|
|
||||||
with:
|
with:
|
||||||
node-version: '16'
|
node-version: '16'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@ -195,14 +180,14 @@ jobs:
|
|||||||
- uses: testspace-com/setup-testspace@v1
|
- uses: testspace-com/setup-testspace@v1
|
||||||
with:
|
with:
|
||||||
domain: ${{github.repository_owner}}
|
domain: ${{github.repository_owner}}
|
||||||
- id: cache-pipenv
|
- id: cache-poetry
|
||||||
uses: actions/cache@v2.1.7
|
uses: actions/cache@v2.1.7
|
||||||
with:
|
with:
|
||||||
path: ~/.local/share/virtualenvs
|
path: ~/.cache/pypoetry/virtualenvs
|
||||||
key: ${{ runner.os }}-pipenv-v2-${{ hashFiles('**/Pipfile.lock') }}
|
key: ${{ runner.os }}-poetry-cache-v2-${{ hashFiles('**/poetry.lock') }}
|
||||||
- name: prepare
|
- name: prepare
|
||||||
env:
|
env:
|
||||||
INSTALL: ${{ steps.cache-pipenv.outputs.cache-hit }}
|
INSTALL: ${{ steps.cache-poetry.outputs.cache-hit }}
|
||||||
run: |
|
run: |
|
||||||
scripts/ci_prepare.sh
|
scripts/ci_prepare.sh
|
||||||
docker-compose -f tests/e2e/docker-compose.yml up -d
|
docker-compose -f tests/e2e/docker-compose.yml up -d
|
||||||
@ -219,8 +204,8 @@ jobs:
|
|||||||
npm run build
|
npm run build
|
||||||
- name: run e2e
|
- name: run e2e
|
||||||
run: |
|
run: |
|
||||||
pipenv run make test-e2e-provider
|
poetry run make test-e2e-provider
|
||||||
pipenv run coverage xml
|
poetry run coverage xml
|
||||||
- name: run testspace
|
- name: run testspace
|
||||||
if: ${{ always() }}
|
if: ${{ always() }}
|
||||||
run: |
|
run: |
|
||||||
@ -230,11 +215,9 @@ jobs:
|
|||||||
test-e2e-rest:
|
test-e2e-rest:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v3
|
||||||
with:
|
- uses: actions/setup-node@v3.0.0
|
||||||
python-version: '3.9'
|
|
||||||
- uses: actions/setup-node@v2
|
|
||||||
with:
|
with:
|
||||||
node-version: '16'
|
node-version: '16'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@ -242,14 +225,14 @@ jobs:
|
|||||||
- uses: testspace-com/setup-testspace@v1
|
- uses: testspace-com/setup-testspace@v1
|
||||||
with:
|
with:
|
||||||
domain: ${{github.repository_owner}}
|
domain: ${{github.repository_owner}}
|
||||||
- id: cache-pipenv
|
- id: cache-poetry
|
||||||
uses: actions/cache@v2.1.7
|
uses: actions/cache@v2.1.7
|
||||||
with:
|
with:
|
||||||
path: ~/.local/share/virtualenvs
|
path: ~/.cache/pypoetry/virtualenvs
|
||||||
key: ${{ runner.os }}-pipenv-v2-${{ hashFiles('**/Pipfile.lock') }}
|
key: ${{ runner.os }}-poetry-cache-v2-${{ hashFiles('**/poetry.lock') }}
|
||||||
- name: prepare
|
- name: prepare
|
||||||
env:
|
env:
|
||||||
INSTALL: ${{ steps.cache-pipenv.outputs.cache-hit }}
|
INSTALL: ${{ steps.cache-poetry.outputs.cache-hit }}
|
||||||
run: |
|
run: |
|
||||||
scripts/ci_prepare.sh
|
scripts/ci_prepare.sh
|
||||||
docker-compose -f tests/e2e/docker-compose.yml up -d
|
docker-compose -f tests/e2e/docker-compose.yml up -d
|
||||||
@ -266,8 +249,8 @@ jobs:
|
|||||||
npm run build
|
npm run build
|
||||||
- name: run e2e
|
- name: run e2e
|
||||||
run: |
|
run: |
|
||||||
pipenv run make test-e2e-rest
|
poetry run make test-e2e-rest
|
||||||
pipenv run coverage xml
|
poetry run coverage xml
|
||||||
- name: run testspace
|
- name: run testspace
|
||||||
if: ${{ always() }}
|
if: ${{ always() }}
|
||||||
run: |
|
run: |
|
||||||
@ -296,7 +279,7 @@ jobs:
|
|||||||
arch:
|
arch:
|
||||||
- 'linux/amd64'
|
- 'linux/amd64'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v1.2.0
|
uses: docker/setup-qemu-action@v1.2.0
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
|
26
.github/workflows/ci-outpost.yml
vendored
26
.github/workflows/ci-outpost.yml
vendored
@ -14,7 +14,7 @@ jobs:
|
|||||||
lint-golint:
|
lint-golint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: "^1.17"
|
go-version: "^1.17"
|
||||||
@ -28,11 +28,27 @@ jobs:
|
|||||||
--rm \
|
--rm \
|
||||||
-v $(pwd):/app \
|
-v $(pwd):/app \
|
||||||
-w /app \
|
-w /app \
|
||||||
golangci/golangci-lint:v1.39.0 \
|
golangci/golangci-lint:v1.43 \
|
||||||
golangci-lint run -v --timeout 200s
|
golangci-lint run -v --timeout 200s
|
||||||
|
test-unittest:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: "^1.17"
|
||||||
|
- name: Get dependencies
|
||||||
|
run: |
|
||||||
|
go get github.com/axw/gocov/gocov
|
||||||
|
go get github.com/AlekSi/gocov-xml
|
||||||
|
go get github.com/jstemmer/go-junit-report
|
||||||
|
- name: Go unittests
|
||||||
|
run: |
|
||||||
|
go test -timeout 0 -v -race -coverprofile=coverage.out -covermode=atomic -cover ./... | go-junit-report > junit.xml
|
||||||
ci-outpost-mark:
|
ci-outpost-mark:
|
||||||
needs:
|
needs:
|
||||||
- lint-golint
|
- lint-golint
|
||||||
|
- test-unittest
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- run: echo mark
|
- run: echo mark
|
||||||
@ -50,7 +66,7 @@ jobs:
|
|||||||
- 'linux/amd64'
|
- 'linux/amd64'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v1.2.0
|
uses: docker/setup-qemu-action@v1.2.0
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
@ -94,11 +110,11 @@ jobs:
|
|||||||
goos: [linux]
|
goos: [linux]
|
||||||
goarch: [amd64, arm64]
|
goarch: [amd64, arm64]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: "^1.17"
|
go-version: "^1.17"
|
||||||
- uses: actions/setup-node@v2
|
- uses: actions/setup-node@v3.0.0
|
||||||
with:
|
with:
|
||||||
node-version: '16'
|
node-version: '16'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
|
16
.github/workflows/ci-web.yml
vendored
16
.github/workflows/ci-web.yml
vendored
@ -14,8 +14,8 @@ jobs:
|
|||||||
lint-eslint:
|
lint-eslint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-node@v2
|
- uses: actions/setup-node@v3.0.0
|
||||||
with:
|
with:
|
||||||
node-version: '16'
|
node-version: '16'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@ -32,8 +32,8 @@ jobs:
|
|||||||
lint-prettier:
|
lint-prettier:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-node@v2
|
- uses: actions/setup-node@v3.0.0
|
||||||
with:
|
with:
|
||||||
node-version: '16'
|
node-version: '16'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@ -50,8 +50,8 @@ jobs:
|
|||||||
lint-lit-analyse:
|
lint-lit-analyse:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-node@v2
|
- uses: actions/setup-node@v3.0.0
|
||||||
with:
|
with:
|
||||||
node-version: '16'
|
node-version: '16'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@ -78,8 +78,8 @@ jobs:
|
|||||||
- ci-web-mark
|
- ci-web-mark
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-node@v2
|
- uses: actions/setup-node@v3.0.0
|
||||||
with:
|
with:
|
||||||
node-version: '16'
|
node-version: '16'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
|
2
.github/workflows/codeql-analysis.yml
vendored
2
.github/workflows/codeql-analysis.yml
vendored
@ -28,7 +28,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
|
40
.github/workflows/release-publish.yml
vendored
40
.github/workflows/release-publish.yml
vendored
@ -9,7 +9,7 @@ jobs:
|
|||||||
build-server:
|
build-server:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v1.2.0
|
uses: docker/setup-qemu-action@v1.2.0
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
@ -30,21 +30,12 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
push: ${{ github.event_name == 'release' }}
|
push: ${{ github.event_name == 'release' }}
|
||||||
tags: |
|
tags: |
|
||||||
beryju/authentik:2021.12.4,
|
beryju/authentik:2022.3.1,
|
||||||
beryju/authentik:latest,
|
beryju/authentik:latest,
|
||||||
ghcr.io/goauthentik/server:2021.12.4,
|
ghcr.io/goauthentik/server:2022.3.1,
|
||||||
ghcr.io/goauthentik/server:latest
|
ghcr.io/goauthentik/server:latest
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
context: .
|
context: .
|
||||||
- name: Building Docker Image (stable)
|
|
||||||
if: ${{ github.event_name == 'release' && !contains('2021.12.4', 'rc') }}
|
|
||||||
run: |
|
|
||||||
docker pull beryju/authentik:latest
|
|
||||||
docker tag beryju/authentik:latest beryju/authentik:stable
|
|
||||||
docker push beryju/authentik:stable
|
|
||||||
docker pull ghcr.io/goauthentik/server:latest
|
|
||||||
docker tag ghcr.io/goauthentik/server:latest ghcr.io/goauthentik/server:stable
|
|
||||||
docker push ghcr.io/goauthentik/server:stable
|
|
||||||
build-outpost:
|
build-outpost:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
@ -54,7 +45,7 @@ jobs:
|
|||||||
- proxy
|
- proxy
|
||||||
- ldap
|
- ldap
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: "^1.17"
|
go-version: "^1.17"
|
||||||
@ -78,21 +69,12 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
push: ${{ github.event_name == 'release' }}
|
push: ${{ github.event_name == 'release' }}
|
||||||
tags: |
|
tags: |
|
||||||
beryju/authentik-${{ matrix.type }}:2021.12.4,
|
beryju/authentik-${{ matrix.type }}:2022.3.1,
|
||||||
beryju/authentik-${{ matrix.type }}:latest,
|
beryju/authentik-${{ matrix.type }}:latest,
|
||||||
ghcr.io/goauthentik/${{ matrix.type }}:2021.12.4,
|
ghcr.io/goauthentik/${{ matrix.type }}:2022.3.1,
|
||||||
ghcr.io/goauthentik/${{ matrix.type }}:latest
|
ghcr.io/goauthentik/${{ matrix.type }}:latest
|
||||||
file: ${{ matrix.type }}.Dockerfile
|
file: ${{ matrix.type }}.Dockerfile
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
- name: Building Docker Image (stable)
|
|
||||||
if: ${{ github.event_name == 'release' && !contains('2021.12.4', 'rc') }}
|
|
||||||
run: |
|
|
||||||
docker pull beryju/authentik-${{ matrix.type }}:latest
|
|
||||||
docker tag beryju/authentik-${{ matrix.type }}:latest beryju/authentik-${{ matrix.type }}:stable
|
|
||||||
docker push beryju/authentik-${{ matrix.type }}:stable
|
|
||||||
docker pull ghcr.io/goauthentik/${{ matrix.type }}:latest
|
|
||||||
docker tag ghcr.io/goauthentik/${{ matrix.type }}:latest ghcr.io/goauthentik/${{ matrix.type }}:stable
|
|
||||||
docker push ghcr.io/goauthentik/${{ matrix.type }}:stable
|
|
||||||
build-outpost-binary:
|
build-outpost-binary:
|
||||||
timeout-minutes: 120
|
timeout-minutes: 120
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@ -105,11 +87,11 @@ jobs:
|
|||||||
goos: [linux, darwin]
|
goos: [linux, darwin]
|
||||||
goarch: [amd64, arm64]
|
goarch: [amd64, arm64]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: "^1.17"
|
go-version: "^1.17"
|
||||||
- uses: actions/setup-node@v2
|
- uses: actions/setup-node@v3.0.0
|
||||||
with:
|
with:
|
||||||
node-version: '16'
|
node-version: '16'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@ -139,7 +121,7 @@ jobs:
|
|||||||
- build-outpost-binary
|
- build-outpost-binary
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: Run test suite in final docker images
|
- name: Run test suite in final docker images
|
||||||
run: |
|
run: |
|
||||||
echo "PG_PASS=$(openssl rand -base64 32)" >> .env
|
echo "PG_PASS=$(openssl rand -base64 32)" >> .env
|
||||||
@ -155,7 +137,7 @@ jobs:
|
|||||||
- build-outpost-binary
|
- build-outpost-binary
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: Get static files from docker image
|
- name: Get static files from docker image
|
||||||
run: |
|
run: |
|
||||||
docker pull ghcr.io/goauthentik/server:latest
|
docker pull ghcr.io/goauthentik/server:latest
|
||||||
@ -170,7 +152,7 @@ jobs:
|
|||||||
SENTRY_PROJECT: authentik
|
SENTRY_PROJECT: authentik
|
||||||
SENTRY_URL: https://sentry.beryju.org
|
SENTRY_URL: https://sentry.beryju.org
|
||||||
with:
|
with:
|
||||||
version: authentik@2021.12.4
|
version: authentik@2022.3.1
|
||||||
environment: beryjuorg-prod
|
environment: beryjuorg-prod
|
||||||
sourcemaps: './web/dist'
|
sourcemaps: './web/dist'
|
||||||
url_prefix: '~/static/dist'
|
url_prefix: '~/static/dist'
|
||||||
|
4
.github/workflows/release-tag.yml
vendored
4
.github/workflows/release-tag.yml
vendored
@ -10,7 +10,7 @@ jobs:
|
|||||||
name: Create Release from Tag
|
name: Create Release from Tag
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: Pre-release test
|
- name: Pre-release test
|
||||||
run: |
|
run: |
|
||||||
echo "PG_PASS=$(openssl rand -base64 32)" >> .env
|
echo "PG_PASS=$(openssl rand -base64 32)" >> .env
|
||||||
@ -27,7 +27,7 @@ jobs:
|
|||||||
docker-compose run -u root server test
|
docker-compose run -u root server test
|
||||||
- name: Extract version number
|
- name: Extract version number
|
||||||
id: get_version
|
id: get_version
|
||||||
uses: actions/github-script@v5
|
uses: actions/github-script@v6
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
script: |
|
script: |
|
||||||
|
16
.github/workflows/translation-compile.yml
vendored
16
.github/workflows/translation-compile.yml
vendored
@ -20,24 +20,22 @@ jobs:
|
|||||||
compile:
|
compile:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v3
|
||||||
with:
|
- id: cache-poetry
|
||||||
python-version: '3.9'
|
|
||||||
- id: cache-pipenv
|
|
||||||
uses: actions/cache@v2.1.7
|
uses: actions/cache@v2.1.7
|
||||||
with:
|
with:
|
||||||
path: ~/.local/share/virtualenvs
|
path: ~/.cache/pypoetry/virtualenvs
|
||||||
key: ${{ runner.os }}-pipenv-v2-${{ hashFiles('**/Pipfile.lock') }}
|
key: ${{ runner.os }}-poetry-cache-v2-${{ hashFiles('**/poetry.lock') }}
|
||||||
- name: prepare
|
- name: prepare
|
||||||
env:
|
env:
|
||||||
INSTALL: ${{ steps.cache-pipenv.outputs.cache-hit }}
|
INSTALL: ${{ steps.cache-poetry.outputs.cache-hit }}
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y gettext
|
sudo apt-get install -y gettext
|
||||||
scripts/ci_prepare.sh
|
scripts/ci_prepare.sh
|
||||||
- name: run compile
|
- name: run compile
|
||||||
run: pipenv run ./manage.py compilemessages
|
run: poetry run ./manage.py compilemessages
|
||||||
- name: Create Pull Request
|
- name: Create Pull Request
|
||||||
uses: peter-evans/create-pull-request@v3
|
uses: peter-evans/create-pull-request@v3
|
||||||
id: cpr
|
id: cpr
|
||||||
|
4
.github/workflows/web-api-publish.yml
vendored
4
.github/workflows/web-api-publish.yml
vendored
@ -8,9 +8,9 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
# Setup .npmrc file to publish to npm
|
# Setup .npmrc file to publish to npm
|
||||||
- uses: actions/setup-node@v2
|
- uses: actions/setup-node@v3.0.0
|
||||||
with:
|
with:
|
||||||
node-version: '16'
|
node-version: '16'
|
||||||
registry-url: 'https://registry.npmjs.org'
|
registry-url: 'https://registry.npmjs.org'
|
||||||
|
@ -1 +0,0 @@
|
|||||||
3.9.7
|
|
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -12,7 +12,8 @@
|
|||||||
"totp",
|
"totp",
|
||||||
"webauthn",
|
"webauthn",
|
||||||
"traefik",
|
"traefik",
|
||||||
"passwordless"
|
"passwordless",
|
||||||
|
"kubernetes"
|
||||||
],
|
],
|
||||||
"python.linting.pylintEnabled": true,
|
"python.linting.pylintEnabled": true,
|
||||||
"todo-tree.tree.showCountsInTree": true,
|
"todo-tree.tree.showCountsInTree": true,
|
||||||
|
43
Dockerfile
43
Dockerfile
@ -1,16 +1,4 @@
|
|||||||
# Stage 1: Lock python dependencies
|
# Stage 1: Build website
|
||||||
FROM docker.io/python:3.10.1-slim-bullseye as locker
|
|
||||||
|
|
||||||
COPY ./Pipfile /app/
|
|
||||||
COPY ./Pipfile.lock /app/
|
|
||||||
|
|
||||||
WORKDIR /app/
|
|
||||||
|
|
||||||
RUN pip install pipenv && \
|
|
||||||
pipenv lock -r > requirements.txt && \
|
|
||||||
pipenv lock -r --dev-only > requirements-dev.txt
|
|
||||||
|
|
||||||
# Stage 2: Build website
|
|
||||||
FROM --platform=${BUILDPLATFORM} docker.io/node:16 as website-builder
|
FROM --platform=${BUILDPLATFORM} docker.io/node:16 as website-builder
|
||||||
|
|
||||||
COPY ./website /work/website/
|
COPY ./website /work/website/
|
||||||
@ -18,7 +6,7 @@ COPY ./website /work/website/
|
|||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
RUN cd /work/website && npm i && npm run build-docs-only
|
RUN cd /work/website && npm i && npm run build-docs-only
|
||||||
|
|
||||||
# Stage 3: Build webui
|
# Stage 2: Build webui
|
||||||
FROM --platform=${BUILDPLATFORM} docker.io/node:16 as web-builder
|
FROM --platform=${BUILDPLATFORM} docker.io/node:16 as web-builder
|
||||||
|
|
||||||
COPY ./web /work/web/
|
COPY ./web /work/web/
|
||||||
@ -27,8 +15,8 @@ COPY ./website /work/website/
|
|||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
RUN cd /work/web && npm i && npm run build
|
RUN cd /work/web && npm i && npm run build
|
||||||
|
|
||||||
# Stage 4: Build go proxy
|
# Stage 3: Build go proxy
|
||||||
FROM docker.io/golang:1.17.5-bullseye AS builder
|
FROM docker.io/golang:1.17.8-bullseye AS builder
|
||||||
|
|
||||||
WORKDIR /work
|
WORKDIR /work
|
||||||
|
|
||||||
@ -43,29 +31,38 @@ COPY ./go.sum /work/go.sum
|
|||||||
|
|
||||||
RUN go build -o /work/authentik ./cmd/server/main.go
|
RUN go build -o /work/authentik ./cmd/server/main.go
|
||||||
|
|
||||||
# Stage 5: Run
|
# Stage 4: Run
|
||||||
FROM docker.io/python:3.10.1-slim-bullseye
|
FROM docker.io/python:3.10.2-slim-bullseye
|
||||||
|
|
||||||
|
LABEL org.opencontainers.image.url https://goauthentik.io
|
||||||
|
LABEL org.opencontainers.image.description goauthentik.io Main server image, see https://goauthentik.io for more info.
|
||||||
|
LABEL org.opencontainers.image.source https://github.com/goauthentik/authentik
|
||||||
|
|
||||||
WORKDIR /
|
WORKDIR /
|
||||||
COPY --from=locker /app/requirements.txt /
|
|
||||||
COPY --from=locker /app/requirements-dev.txt /
|
|
||||||
|
|
||||||
ARG GIT_BUILD_HASH
|
ARG GIT_BUILD_HASH
|
||||||
ENV GIT_BUILD_HASH=$GIT_BUILD_HASH
|
ENV GIT_BUILD_HASH=$GIT_BUILD_HASH
|
||||||
|
|
||||||
|
COPY ./pyproject.toml /
|
||||||
|
COPY ./poetry.lock /
|
||||||
|
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install -y --no-install-recommends \
|
apt-get install -y --no-install-recommends \
|
||||||
curl ca-certificates gnupg git runit libpq-dev \
|
curl ca-certificates gnupg git runit libpq-dev \
|
||||||
postgresql-client build-essential libxmlsec1-dev \
|
postgresql-client build-essential libxmlsec1-dev \
|
||||||
pkg-config libmaxminddb0 && \
|
pkg-config libmaxminddb0 && \
|
||||||
pip install -r /requirements.txt --no-cache-dir && \
|
pip install poetry && \
|
||||||
|
poetry config virtualenvs.create false && \
|
||||||
|
poetry install --no-dev && \
|
||||||
|
rm -rf ~/.cache/pypoetry && \
|
||||||
apt-get remove --purge -y build-essential git && \
|
apt-get remove --purge -y build-essential git && \
|
||||||
apt-get autoremove --purge -y && \
|
apt-get autoremove --purge -y && \
|
||||||
apt-get clean && \
|
apt-get clean && \
|
||||||
rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/ && \
|
rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/ && \
|
||||||
adduser --system --no-create-home --uid 1000 --group --home /authentik authentik && \
|
adduser --system --no-create-home --uid 1000 --group --home /authentik authentik && \
|
||||||
mkdir -p /backups /certs /media && \
|
mkdir -p /certs /media && \
|
||||||
chown authentik:authentik /backups /certs /media
|
mkdir -p /authentik/.ssh && \
|
||||||
|
chown authentik:authentik /certs /media /authentik/.ssh
|
||||||
|
|
||||||
COPY ./authentik/ /authentik
|
COPY ./authentik/ /authentik
|
||||||
COPY ./pyproject.toml /
|
COPY ./pyproject.toml /
|
||||||
|
24
Makefile
24
Makefile
@ -15,6 +15,9 @@ test-e2e-provider:
|
|||||||
test-e2e-rest:
|
test-e2e-rest:
|
||||||
coverage run manage.py test tests/e2e/test_flows* tests/e2e/test_source*
|
coverage run manage.py test tests/e2e/test_flows* tests/e2e/test_source*
|
||||||
|
|
||||||
|
test-go:
|
||||||
|
go test -timeout 0 -v -race -cover ./...
|
||||||
|
|
||||||
test:
|
test:
|
||||||
coverage run manage.py test authentik
|
coverage run manage.py test authentik
|
||||||
coverage html
|
coverage html
|
||||||
@ -106,20 +109,29 @@ web-extract:
|
|||||||
# These targets are use by GitHub actions to allow usage of matrix
|
# These targets are use by GitHub actions to allow usage of matrix
|
||||||
# which makes the YAML File a lot smaller
|
# which makes the YAML File a lot smaller
|
||||||
|
|
||||||
ci-pylint:
|
ci--meta-debug:
|
||||||
|
python -V
|
||||||
|
node --version
|
||||||
|
|
||||||
|
ci-pylint: ci--meta-debug
|
||||||
pylint authentik tests lifecycle
|
pylint authentik tests lifecycle
|
||||||
|
|
||||||
ci-black:
|
ci-black: ci--meta-debug
|
||||||
black --check authentik tests lifecycle
|
black --check authentik tests lifecycle
|
||||||
|
|
||||||
ci-isort:
|
ci-isort: ci--meta-debug
|
||||||
isort --check authentik tests lifecycle
|
isort --check authentik tests lifecycle
|
||||||
|
|
||||||
ci-bandit:
|
ci-bandit: ci--meta-debug
|
||||||
bandit -r authentik tests lifecycle
|
bandit -r authentik tests lifecycle
|
||||||
|
|
||||||
ci-pyright:
|
ci-pyright: ci--meta-debug
|
||||||
pyright e2e lifecycle
|
pyright e2e lifecycle
|
||||||
|
|
||||||
ci-pending-migrations:
|
ci-pending-migrations: ci--meta-debug
|
||||||
./manage.py makemigrations --check
|
./manage.py makemigrations --check
|
||||||
|
|
||||||
|
install:
|
||||||
|
poetry install
|
||||||
|
cd web && npm i
|
||||||
|
cd website && npm i
|
||||||
|
68
Pipfile
68
Pipfile
@ -1,68 +0,0 @@
|
|||||||
[[source]]
|
|
||||||
name = "pypi"
|
|
||||||
url = "https://pypi.org/simple"
|
|
||||||
verify_ssl = true
|
|
||||||
|
|
||||||
[packages]
|
|
||||||
boto3 = "*"
|
|
||||||
celery = "*"
|
|
||||||
channels = "*"
|
|
||||||
channels-redis = "*"
|
|
||||||
codespell = "*"
|
|
||||||
colorama = "*"
|
|
||||||
dacite = "*"
|
|
||||||
deepmerge = "*"
|
|
||||||
defusedxml = "*"
|
|
||||||
django = "*"
|
|
||||||
django-dbbackup = { git = 'https://github.com/django-dbbackup/django-dbbackup.git', ref = '9d1909c30a3271c8c9c8450add30d6e0b996e145' }
|
|
||||||
django-filter = "*"
|
|
||||||
django-guardian = "*"
|
|
||||||
django-model-utils = "*"
|
|
||||||
django-otp = "*"
|
|
||||||
django-prometheus = "*"
|
|
||||||
django-redis = "*"
|
|
||||||
django-storages = "*"
|
|
||||||
djangorestframework = "*"
|
|
||||||
djangorestframework-guardian = "*"
|
|
||||||
docker = "*"
|
|
||||||
drf-spectacular = "*"
|
|
||||||
duo-client = "*"
|
|
||||||
facebook-sdk = "*"
|
|
||||||
geoip2 = "*"
|
|
||||||
gunicorn = "*"
|
|
||||||
kubernetes = "==v19.15.0"
|
|
||||||
ldap3 = "*"
|
|
||||||
lxml = "*"
|
|
||||||
packaging = "*"
|
|
||||||
psycopg2-binary = "*"
|
|
||||||
pycryptodome = "*"
|
|
||||||
pyjwt = "*"
|
|
||||||
pyyaml = "*"
|
|
||||||
requests-oauthlib = "*"
|
|
||||||
sentry-sdk = { git = 'https://github.com/beryju/sentry-python.git', ref = '379aee28b15d3b87b381317746c4efd24b3d7bc3' }
|
|
||||||
service_identity = "*"
|
|
||||||
structlog = "*"
|
|
||||||
swagger-spec-validator = "*"
|
|
||||||
twisted = "==21.7.0"
|
|
||||||
ua-parser = "*"
|
|
||||||
urllib3 = {extras = ["secure"],version = "*"}
|
|
||||||
uvicorn = {extras = ["standard"],version = "*"}
|
|
||||||
webauthn = "*"
|
|
||||||
xmlsec = "*"
|
|
||||||
flower = "*"
|
|
||||||
wsproto = "*"
|
|
||||||
|
|
||||||
[dev-packages]
|
|
||||||
bandit = "*"
|
|
||||||
black = "==21.11b1"
|
|
||||||
bump2version = "*"
|
|
||||||
colorama = "*"
|
|
||||||
coverage = {extras = ["toml"],version = "*"}
|
|
||||||
pylint = "*"
|
|
||||||
pylint-django = "*"
|
|
||||||
pytest = "*"
|
|
||||||
pytest-django = "*"
|
|
||||||
pytest-randomly = "*"
|
|
||||||
requests-mock = "*"
|
|
||||||
selenium = "*"
|
|
||||||
importlib-metadata = "*"
|
|
2583
Pipfile.lock
generated
2583
Pipfile.lock
generated
File diff suppressed because it is too large
Load Diff
@ -57,4 +57,4 @@ DigitalOcean provides development and testing resources for authentik.
|
|||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
Netlify hosts the [goauthentik.io](goauthentik.io) site.
|
Netlify hosts the [goauthentik.io](https://goauthentik.io) site.
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
| Version | Supported |
|
| Version | Supported |
|
||||||
| ---------- | ------------------ |
|
| ---------- | ------------------ |
|
||||||
| 2021.10.x | :white_check_mark: |
|
| 2022.1.x | :white_check_mark: |
|
||||||
| 2021.12.x | :white_check_mark: |
|
| 2022.2.x | :white_check_mark: |
|
||||||
|
|
||||||
## Reporting a Vulnerability
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
"""authentik"""
|
"""authentik"""
|
||||||
__version__ = "2021.12.4"
|
from os import environ
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
__version__ = "2022.3.1"
|
||||||
ENV_GIT_HASH_KEY = "GIT_BUILD_HASH"
|
ENV_GIT_HASH_KEY = "GIT_BUILD_HASH"
|
||||||
|
|
||||||
|
|
||||||
|
def get_build_hash(fallback: Optional[str] = None) -> str:
|
||||||
|
"""Get build hash"""
|
||||||
|
return environ.get(ENV_GIT_HASH_KEY, fallback if fallback else "")
|
||||||
|
|
||||||
|
|
||||||
|
def get_full_version() -> str:
|
||||||
|
"""Get full version, with build hash appended"""
|
||||||
|
version = __version__
|
||||||
|
if (build_hash := get_build_hash()) != "":
|
||||||
|
version += "." + build_hash
|
||||||
|
return version
|
||||||
|
@ -12,10 +12,13 @@ from rest_framework.permissions import IsAdminUser
|
|||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.viewsets import ViewSet
|
from rest_framework.viewsets import ViewSet
|
||||||
|
from structlog.stdlib import get_logger
|
||||||
|
|
||||||
from authentik.core.api.utils import PassiveSerializer
|
from authentik.core.api.utils import PassiveSerializer
|
||||||
from authentik.events.monitored_tasks import TaskInfo, TaskResultStatus
|
from authentik.events.monitored_tasks import TaskInfo, TaskResultStatus
|
||||||
|
|
||||||
|
LOGGER = get_logger()
|
||||||
|
|
||||||
|
|
||||||
class TaskSerializer(PassiveSerializer):
|
class TaskSerializer(PassiveSerializer):
|
||||||
"""Serialize TaskInfo and TaskResult"""
|
"""Serialize TaskInfo and TaskResult"""
|
||||||
@ -89,13 +92,15 @@ class TaskViewSet(ViewSet):
|
|||||||
try:
|
try:
|
||||||
task_module = import_module(task.task_call_module)
|
task_module = import_module(task.task_call_module)
|
||||||
task_func = getattr(task_module, task.task_call_func)
|
task_func = getattr(task_module, task.task_call_func)
|
||||||
|
LOGGER.debug("Running task", task=task_func)
|
||||||
task_func.delay(*task.task_call_args, **task.task_call_kwargs)
|
task_func.delay(*task.task_call_args, **task.task_call_kwargs)
|
||||||
messages.success(
|
messages.success(
|
||||||
self.request,
|
self.request,
|
||||||
_("Successfully re-scheduled Task %(name)s!" % {"name": task.task_name}),
|
_("Successfully re-scheduled Task %(name)s!" % {"name": task.task_name}),
|
||||||
)
|
)
|
||||||
return Response(status=204)
|
return Response(status=204)
|
||||||
except ImportError: # pragma: no cover
|
except (ImportError, AttributeError): # pragma: no cover
|
||||||
|
LOGGER.warning("Failed to run task, remove state", task=task)
|
||||||
# if we get an import error, the module path has probably changed
|
# if we get an import error, the module path has probably changed
|
||||||
task.delete()
|
task.delete()
|
||||||
return Response(status=500)
|
return Response(status=500)
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
"""authentik administration overview"""
|
"""authentik administration overview"""
|
||||||
from os import environ
|
|
||||||
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from drf_spectacular.utils import extend_schema
|
from drf_spectacular.utils import extend_schema
|
||||||
from packaging.version import parse
|
from packaging.version import parse
|
||||||
@ -10,7 +8,7 @@ from rest_framework.request import Request
|
|||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
from authentik import ENV_GIT_HASH_KEY, __version__
|
from authentik import __version__, get_build_hash
|
||||||
from authentik.admin.tasks import VERSION_CACHE_KEY, update_latest_version
|
from authentik.admin.tasks import VERSION_CACHE_KEY, update_latest_version
|
||||||
from authentik.core.api.utils import PassiveSerializer
|
from authentik.core.api.utils import PassiveSerializer
|
||||||
|
|
||||||
@ -25,7 +23,7 @@ class VersionSerializer(PassiveSerializer):
|
|||||||
|
|
||||||
def get_build_hash(self, _) -> str:
|
def get_build_hash(self, _) -> str:
|
||||||
"""Get build hash, if version is not latest or released"""
|
"""Get build hash, if version is not latest or released"""
|
||||||
return environ.get(ENV_GIT_HASH_KEY, "")
|
return get_build_hash()
|
||||||
|
|
||||||
def get_version_current(self, _) -> str:
|
def get_version_current(self, _) -> str:
|
||||||
"""Get current version"""
|
"""Get current version"""
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""authentik admin app config"""
|
"""authentik admin app config"""
|
||||||
|
from importlib import import_module
|
||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
@ -13,3 +15,4 @@ class AuthentikAdminConfig(AppConfig):
|
|||||||
from authentik.admin.tasks import clear_update_notifications
|
from authentik.admin.tasks import clear_update_notifications
|
||||||
|
|
||||||
clear_update_notifications.delay()
|
clear_update_notifications.delay()
|
||||||
|
import_module("authentik.admin.signals")
|
||||||
|
23
authentik/admin/signals.py
Normal file
23
authentik/admin/signals.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
"""admin signals"""
|
||||||
|
from django.dispatch import receiver
|
||||||
|
|
||||||
|
from authentik.admin.api.tasks import TaskInfo
|
||||||
|
from authentik.admin.api.workers import GAUGE_WORKERS
|
||||||
|
from authentik.root.celery import CELERY_APP
|
||||||
|
from authentik.root.monitoring import monitoring_set
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(monitoring_set)
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def monitoring_set_workers(sender, **kwargs):
|
||||||
|
"""Set worker gauge"""
|
||||||
|
count = len(CELERY_APP.control.ping(timeout=0.5))
|
||||||
|
GAUGE_WORKERS.set(count)
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(monitoring_set)
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def monitoring_set_tasks(sender, **kwargs):
|
||||||
|
"""Set task gauges"""
|
||||||
|
for task in TaskInfo.all().values():
|
||||||
|
task.set_prom_metrics()
|
@ -1,6 +1,5 @@
|
|||||||
"""authentik admin tasks"""
|
"""authentik admin tasks"""
|
||||||
import re
|
import re
|
||||||
from os import environ
|
|
||||||
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.core.validators import URLValidator
|
from django.core.validators import URLValidator
|
||||||
@ -9,7 +8,7 @@ from prometheus_client import Info
|
|||||||
from requests import RequestException
|
from requests import RequestException
|
||||||
from structlog.stdlib import get_logger
|
from structlog.stdlib import get_logger
|
||||||
|
|
||||||
from authentik import ENV_GIT_HASH_KEY, __version__
|
from authentik import __version__, get_build_hash
|
||||||
from authentik.events.models import Event, EventAction, Notification
|
from authentik.events.models import Event, EventAction, Notification
|
||||||
from authentik.events.monitored_tasks import (
|
from authentik.events.monitored_tasks import (
|
||||||
MonitoredTask,
|
MonitoredTask,
|
||||||
@ -36,7 +35,7 @@ def _set_prom_info():
|
|||||||
{
|
{
|
||||||
"version": __version__,
|
"version": __version__,
|
||||||
"latest": cache.get(VERSION_CACHE_KEY, ""),
|
"latest": cache.get(VERSION_CACHE_KEY, ""),
|
||||||
"build_hash": environ.get(ENV_GIT_HASH_KEY, ""),
|
"build_hash": get_build_hash(),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""API Authentication"""
|
"""API Authentication"""
|
||||||
from base64 import b64decode
|
from base64 import b64decode
|
||||||
from binascii import Error
|
from binascii import Error
|
||||||
from typing import Any, Optional, Union
|
from typing import Any, Optional
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from rest_framework.authentication import BaseAuthentication, get_authorization_header
|
from rest_framework.authentication import BaseAuthentication, get_authorization_header
|
||||||
@ -69,7 +69,7 @@ def token_secret_key(value: str) -> Optional[User]:
|
|||||||
class TokenAuthentication(BaseAuthentication):
|
class TokenAuthentication(BaseAuthentication):
|
||||||
"""Token-based authentication using HTTP Bearer authentication"""
|
"""Token-based authentication using HTTP Bearer authentication"""
|
||||||
|
|
||||||
def authenticate(self, request: Request) -> Union[tuple[User, Any], None]:
|
def authenticate(self, request: Request) -> tuple[User, Any] | None:
|
||||||
"""Token-based authentication using HTTP Bearer authentication"""
|
"""Token-based authentication using HTTP Bearer authentication"""
|
||||||
auth = get_authorization_header(request)
|
auth = get_authorization_header(request)
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ function getCookie(name) {
|
|||||||
window.addEventListener('DOMContentLoaded', (event) => {
|
window.addEventListener('DOMContentLoaded', (event) => {
|
||||||
const rapidocEl = document.querySelector('rapi-doc');
|
const rapidocEl = document.querySelector('rapi-doc');
|
||||||
rapidocEl.addEventListener('before-try', (e) => {
|
rapidocEl.addEventListener('before-try', (e) => {
|
||||||
e.detail.request.headers.append('X-CSRFToken', getCookie("authentik_csrf"));
|
e.detail.request.headers.append('X-authentik-CSRF', getCookie("authentik_csrf"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -4,7 +4,5 @@ from django.urls import include, path
|
|||||||
from authentik.api.v3.urls import urlpatterns as v3_urls
|
from authentik.api.v3.urls import urlpatterns as v3_urls
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# TODO: Remove in 2022.1
|
|
||||||
path("v2beta/", include(v3_urls)),
|
|
||||||
path("v3/", include(v3_urls)),
|
path("v3/", include(v3_urls)),
|
||||||
]
|
]
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
"""core Configs API"""
|
"""core Configs API"""
|
||||||
from os import environ, path
|
from os import path
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from drf_spectacular.utils import extend_schema
|
from drf_spectacular.utils import extend_schema
|
||||||
from kubernetes.config.incluster_config import SERVICE_HOST_ENV_NAME
|
|
||||||
from rest_framework.fields import (
|
from rest_framework.fields import (
|
||||||
BooleanField,
|
BooleanField,
|
||||||
CharField,
|
CharField,
|
||||||
@ -28,7 +27,6 @@ class Capabilities(models.TextChoices):
|
|||||||
|
|
||||||
CAN_SAVE_MEDIA = "can_save_media"
|
CAN_SAVE_MEDIA = "can_save_media"
|
||||||
CAN_GEO_IP = "can_geo_ip"
|
CAN_GEO_IP = "can_geo_ip"
|
||||||
CAN_BACKUP = "can_backup"
|
|
||||||
|
|
||||||
|
|
||||||
class ErrorReportingConfigSerializer(PassiveSerializer):
|
class ErrorReportingConfigSerializer(PassiveSerializer):
|
||||||
@ -65,13 +63,6 @@ class ConfigView(APIView):
|
|||||||
caps.append(Capabilities.CAN_SAVE_MEDIA)
|
caps.append(Capabilities.CAN_SAVE_MEDIA)
|
||||||
if GEOIP_READER.enabled:
|
if GEOIP_READER.enabled:
|
||||||
caps.append(Capabilities.CAN_GEO_IP)
|
caps.append(Capabilities.CAN_GEO_IP)
|
||||||
if SERVICE_HOST_ENV_NAME in environ:
|
|
||||||
# Running in k8s, only s3 backup is supported
|
|
||||||
if CONFIG.y("postgresql.s3_backup"):
|
|
||||||
caps.append(Capabilities.CAN_BACKUP)
|
|
||||||
else:
|
|
||||||
# Running in compose, backup is always supported
|
|
||||||
caps.append(Capabilities.CAN_BACKUP)
|
|
||||||
return caps
|
return caps
|
||||||
|
|
||||||
@extend_schema(responses={200: ConfigSerializer(many=False)})
|
@extend_schema(responses={200: ConfigSerializer(many=False)})
|
||||||
@ -80,7 +71,7 @@ class ConfigView(APIView):
|
|||||||
config = ConfigSerializer(
|
config = ConfigSerializer(
|
||||||
{
|
{
|
||||||
"error_reporting": {
|
"error_reporting": {
|
||||||
"enabled": CONFIG.y("error_reporting.enabled"),
|
"enabled": CONFIG.y("error_reporting.enabled") and not settings.DEBUG,
|
||||||
"environment": CONFIG.y("error_reporting.environment"),
|
"environment": CONFIG.y("error_reporting.environment"),
|
||||||
"send_pii": CONFIG.y("error_reporting.send_pii"),
|
"send_pii": CONFIG.y("error_reporting.send_pii"),
|
||||||
"traces_sample_rate": float(CONFIG.y("error_reporting.sample_rate", 0.4)),
|
"traces_sample_rate": float(CONFIG.y("error_reporting.sample_rate", 0.4)),
|
||||||
|
@ -46,11 +46,7 @@ from authentik.policies.expiry.api import PasswordExpiryPolicyViewSet
|
|||||||
from authentik.policies.expression.api import ExpressionPolicyViewSet
|
from authentik.policies.expression.api import ExpressionPolicyViewSet
|
||||||
from authentik.policies.hibp.api import HaveIBeenPwendPolicyViewSet
|
from authentik.policies.hibp.api import HaveIBeenPwendPolicyViewSet
|
||||||
from authentik.policies.password.api import PasswordPolicyViewSet
|
from authentik.policies.password.api import PasswordPolicyViewSet
|
||||||
from authentik.policies.reputation.api import (
|
from authentik.policies.reputation.api import ReputationPolicyViewSet, ReputationViewSet
|
||||||
IPReputationViewSet,
|
|
||||||
ReputationPolicyViewSet,
|
|
||||||
UserReputationViewSet,
|
|
||||||
)
|
|
||||||
from authentik.providers.ldap.api import LDAPOutpostConfigViewSet, LDAPProviderViewSet
|
from authentik.providers.ldap.api import LDAPOutpostConfigViewSet, LDAPProviderViewSet
|
||||||
from authentik.providers.oauth2.api.provider import OAuth2ProviderViewSet
|
from authentik.providers.oauth2.api.provider import OAuth2ProviderViewSet
|
||||||
from authentik.providers.oauth2.api.scope import ScopeMappingViewSet
|
from authentik.providers.oauth2.api.scope import ScopeMappingViewSet
|
||||||
@ -151,8 +147,7 @@ router.register("policies/event_matcher", EventMatcherPolicyViewSet)
|
|||||||
router.register("policies/haveibeenpwned", HaveIBeenPwendPolicyViewSet)
|
router.register("policies/haveibeenpwned", HaveIBeenPwendPolicyViewSet)
|
||||||
router.register("policies/password_expiry", PasswordExpiryPolicyViewSet)
|
router.register("policies/password_expiry", PasswordExpiryPolicyViewSet)
|
||||||
router.register("policies/password", PasswordPolicyViewSet)
|
router.register("policies/password", PasswordPolicyViewSet)
|
||||||
router.register("policies/reputation/users", UserReputationViewSet)
|
router.register("policies/reputation/scores", ReputationViewSet)
|
||||||
router.register("policies/reputation/ips", IPReputationViewSet)
|
|
||||||
router.register("policies/reputation", ReputationPolicyViewSet)
|
router.register("policies/reputation", ReputationPolicyViewSet)
|
||||||
|
|
||||||
router.register("providers/all", ProviderViewSet)
|
router.register("providers/all", ProviderViewSet)
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""Application API Views"""
|
"""Application API Views"""
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.db.models import QuerySet
|
from django.db.models import QuerySet
|
||||||
from django.http.response import HttpResponseBadRequest
|
from django.http.response import HttpResponseBadRequest
|
||||||
@ -7,7 +9,7 @@ from drf_spectacular.types import OpenApiTypes
|
|||||||
from drf_spectacular.utils import OpenApiParameter, OpenApiResponse, extend_schema
|
from drf_spectacular.utils import OpenApiParameter, OpenApiResponse, extend_schema
|
||||||
from guardian.shortcuts import get_objects_for_user
|
from guardian.shortcuts import get_objects_for_user
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.fields import ReadOnlyField
|
from rest_framework.fields import ReadOnlyField, SerializerMethodField
|
||||||
from rest_framework.parsers import MultiPartParser
|
from rest_framework.parsers import MultiPartParser
|
||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
@ -39,11 +41,16 @@ def user_app_cache_key(user_pk: str) -> str:
|
|||||||
class ApplicationSerializer(ModelSerializer):
|
class ApplicationSerializer(ModelSerializer):
|
||||||
"""Application Serializer"""
|
"""Application Serializer"""
|
||||||
|
|
||||||
launch_url = ReadOnlyField(source="get_launch_url")
|
launch_url = SerializerMethodField()
|
||||||
provider_obj = ProviderSerializer(source="get_provider", required=False)
|
provider_obj = ProviderSerializer(source="get_provider", required=False)
|
||||||
|
|
||||||
meta_icon = ReadOnlyField(source="get_meta_icon")
|
meta_icon = ReadOnlyField(source="get_meta_icon")
|
||||||
|
|
||||||
|
def get_launch_url(self, app: Application) -> Optional[str]:
|
||||||
|
"""Allow formatting of launch URL"""
|
||||||
|
user = self.context["request"].user
|
||||||
|
return app.get_launch_url(user)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
||||||
model = Application
|
model = Application
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
"""Tokens API Viewset"""
|
"""Tokens API Viewset"""
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from django.http.response import Http404
|
|
||||||
from django_filters.rest_framework import DjangoFilterBackend
|
from django_filters.rest_framework import DjangoFilterBackend
|
||||||
from drf_spectacular.utils import OpenApiResponse, extend_schema
|
from drf_spectacular.utils import OpenApiResponse, extend_schema
|
||||||
from guardian.shortcuts import get_anonymous_user
|
from guardian.shortcuts import assign_perm, get_anonymous_user
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.exceptions import ValidationError
|
from rest_framework.exceptions import ValidationError
|
||||||
from rest_framework.fields import CharField
|
from rest_framework.fields import CharField
|
||||||
@ -96,10 +95,12 @@ class TokenViewSet(UsedByMixin, ModelViewSet):
|
|||||||
|
|
||||||
def perform_create(self, serializer: TokenSerializer):
|
def perform_create(self, serializer: TokenSerializer):
|
||||||
if not self.request.user.is_superuser:
|
if not self.request.user.is_superuser:
|
||||||
return serializer.save(
|
instance = serializer.save(
|
||||||
user=self.request.user,
|
user=self.request.user,
|
||||||
expiring=self.request.user.attributes.get(USER_ATTRIBUTE_TOKEN_EXPIRING, True),
|
expiring=self.request.user.attributes.get(USER_ATTRIBUTE_TOKEN_EXPIRING, True),
|
||||||
)
|
)
|
||||||
|
assign_perm("authentik_core.view_token_key", self.request.user, instance)
|
||||||
|
return instance
|
||||||
return super().perform_create(serializer)
|
return super().perform_create(serializer)
|
||||||
|
|
||||||
@permission_required("authentik_core.view_token_key")
|
@permission_required("authentik_core.view_token_key")
|
||||||
@ -114,7 +115,5 @@ class TokenViewSet(UsedByMixin, ModelViewSet):
|
|||||||
def view_key(self, request: Request, identifier: str) -> Response:
|
def view_key(self, request: Request, identifier: str) -> Response:
|
||||||
"""Return token key and log access"""
|
"""Return token key and log access"""
|
||||||
token: Token = self.get_object()
|
token: Token = self.get_object()
|
||||||
if token.is_expired:
|
|
||||||
raise Http404
|
|
||||||
Event.new(EventAction.SECRET_VIEW, secret=token).from_http(request) # noqa # nosec
|
Event.new(EventAction.SECRET_VIEW, secret=token).from_http(request) # noqa # nosec
|
||||||
return Response(TokenViewSerializer({"key": token.key}).data)
|
return Response(TokenViewSerializer({"key": token.key}).data)
|
||||||
|
@ -3,6 +3,7 @@ from datetime import timedelta
|
|||||||
from json import loads
|
from json import loads
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
from django.contrib.auth import update_session_auth_hash
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
from django.db.transaction import atomic
|
from django.db.transaction import atomic
|
||||||
from django.db.utils import IntegrityError
|
from django.db.utils import IntegrityError
|
||||||
@ -23,7 +24,6 @@ from drf_spectacular.utils import (
|
|||||||
from guardian.shortcuts import get_anonymous_user, get_objects_for_user
|
from guardian.shortcuts import get_anonymous_user, get_objects_for_user
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.fields import CharField, DictField, JSONField, SerializerMethodField
|
from rest_framework.fields import CharField, DictField, JSONField, SerializerMethodField
|
||||||
from rest_framework.permissions import IsAuthenticated
|
|
||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.serializers import (
|
from rest_framework.serializers import (
|
||||||
@ -45,8 +45,6 @@ from authentik.core.api.used_by import UsedByMixin
|
|||||||
from authentik.core.api.utils import LinkSerializer, PassiveSerializer, is_dict
|
from authentik.core.api.utils import LinkSerializer, PassiveSerializer, is_dict
|
||||||
from authentik.core.middleware import SESSION_IMPERSONATE_ORIGINAL_USER, SESSION_IMPERSONATE_USER
|
from authentik.core.middleware import SESSION_IMPERSONATE_ORIGINAL_USER, SESSION_IMPERSONATE_USER
|
||||||
from authentik.core.models import (
|
from authentik.core.models import (
|
||||||
USER_ATTRIBUTE_CHANGE_EMAIL,
|
|
||||||
USER_ATTRIBUTE_CHANGE_USERNAME,
|
|
||||||
USER_ATTRIBUTE_SA,
|
USER_ATTRIBUTE_SA,
|
||||||
USER_ATTRIBUTE_TOKEN_EXPIRING,
|
USER_ATTRIBUTE_TOKEN_EXPIRING,
|
||||||
Group,
|
Group,
|
||||||
@ -55,7 +53,6 @@ from authentik.core.models import (
|
|||||||
User,
|
User,
|
||||||
)
|
)
|
||||||
from authentik.events.models import EventAction
|
from authentik.events.models import EventAction
|
||||||
from authentik.lib.config import CONFIG
|
|
||||||
from authentik.stages.email.models import EmailStage
|
from authentik.stages.email.models import EmailStage
|
||||||
from authentik.stages.email.tasks import send_mails
|
from authentik.stages.email.tasks import send_mails
|
||||||
from authentik.stages.email.utils import TemplateEmailMessage
|
from authentik.stages.email.utils import TemplateEmailMessage
|
||||||
@ -124,26 +121,6 @@ class UserSelfSerializer(ModelSerializer):
|
|||||||
"pk": group.pk,
|
"pk": group.pk,
|
||||||
}
|
}
|
||||||
|
|
||||||
def validate_email(self, email: str):
|
|
||||||
"""Check if the user is allowed to change their email"""
|
|
||||||
if self.instance.group_attributes().get(
|
|
||||||
USER_ATTRIBUTE_CHANGE_EMAIL, CONFIG.y_bool("default_user_change_email", True)
|
|
||||||
):
|
|
||||||
return email
|
|
||||||
if email != self.instance.email:
|
|
||||||
raise ValidationError("Not allowed to change email.")
|
|
||||||
return email
|
|
||||||
|
|
||||||
def validate_username(self, username: str):
|
|
||||||
"""Check if the user is allowed to change their username"""
|
|
||||||
if self.instance.group_attributes().get(
|
|
||||||
USER_ATTRIBUTE_CHANGE_USERNAME, CONFIG.y_bool("default_user_change_username", True)
|
|
||||||
):
|
|
||||||
return username
|
|
||||||
if username != self.instance.username:
|
|
||||||
raise ValidationError("Not allowed to change username.")
|
|
||||||
return username
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
||||||
model = User
|
model = User
|
||||||
@ -222,6 +199,7 @@ class UsersFilter(FilterSet):
|
|||||||
)
|
)
|
||||||
|
|
||||||
is_superuser = BooleanFilter(field_name="ak_groups", lookup_expr="is_superuser")
|
is_superuser = BooleanFilter(field_name="ak_groups", lookup_expr="is_superuser")
|
||||||
|
uid = CharFilter(field_name="uid")
|
||||||
|
|
||||||
groups_by_name = ModelMultipleChoiceFilter(
|
groups_by_name = ModelMultipleChoiceFilter(
|
||||||
field_name="ak_groups__name",
|
field_name="ak_groups__name",
|
||||||
@ -271,7 +249,7 @@ class UserViewSet(UsedByMixin, ModelViewSet):
|
|||||||
queryset = User.objects.none()
|
queryset = User.objects.none()
|
||||||
ordering = ["username"]
|
ordering = ["username"]
|
||||||
serializer_class = UserSerializer
|
serializer_class = UserSerializer
|
||||||
search_fields = ["username", "name", "is_active", "email"]
|
search_fields = ["username", "name", "is_active", "email", "uid"]
|
||||||
filterset_class = UsersFilter
|
filterset_class = UsersFilter
|
||||||
|
|
||||||
def get_queryset(self): # pragma: no cover
|
def get_queryset(self): # pragma: no cover
|
||||||
@ -359,25 +337,34 @@ class UserViewSet(UsedByMixin, ModelViewSet):
|
|||||||
).data
|
).data
|
||||||
return Response(serializer.initial_data)
|
return Response(serializer.initial_data)
|
||||||
|
|
||||||
@extend_schema(request=UserSelfSerializer, responses={200: SessionUserSerializer(many=False)})
|
@permission_required("authentik_core.reset_user_password")
|
||||||
@action(
|
@extend_schema(
|
||||||
methods=["PUT"],
|
request=inline_serializer(
|
||||||
detail=False,
|
"UserPasswordSetSerializer",
|
||||||
pagination_class=None,
|
{
|
||||||
filter_backends=[],
|
"password": CharField(required=True),
|
||||||
permission_classes=[IsAuthenticated],
|
},
|
||||||
|
),
|
||||||
|
responses={
|
||||||
|
204: "",
|
||||||
|
400: "",
|
||||||
|
},
|
||||||
)
|
)
|
||||||
def update_self(self, request: Request) -> Response:
|
@action(detail=True, methods=["POST"])
|
||||||
"""Allow users to change information on their own profile"""
|
# pylint: disable=invalid-name, unused-argument
|
||||||
data = UserSelfSerializer(instance=User.objects.get(pk=request.user.pk), data=request.data)
|
def set_password(self, request: Request, pk: int) -> Response:
|
||||||
if not data.is_valid():
|
"""Set password for user"""
|
||||||
return Response(data.errors, status=400)
|
user: User = self.get_object()
|
||||||
new_user = data.save()
|
try:
|
||||||
# If we're impersonating, we need to update that user object
|
user.set_password(request.data.get("password"))
|
||||||
# since it caches the full object
|
user.save()
|
||||||
if SESSION_IMPERSONATE_USER in request.session:
|
except (ValidationError, IntegrityError) as exc:
|
||||||
request.session[SESSION_IMPERSONATE_USER] = new_user
|
LOGGER.debug("Failed to set password", exc=exc)
|
||||||
return Response({"user": data.data})
|
return Response(status=400)
|
||||||
|
if user.pk == request.user.pk and SESSION_IMPERSONATE_USER not in self.request.session:
|
||||||
|
LOGGER.debug("Updating session hash after password change")
|
||||||
|
update_session_auth_hash(self.request, user)
|
||||||
|
return Response(status=204)
|
||||||
|
|
||||||
@permission_required("authentik_core.view_user", ["authentik_events.view_event"])
|
@permission_required("authentik_core.view_user", ["authentik_events.view_event"])
|
||||||
@extend_schema(responses={200: UserMetricsSerializer(many=False)})
|
@extend_schema(responses={200: UserMetricsSerializer(many=False)})
|
||||||
|
@ -30,7 +30,7 @@ class InbuiltBackend(ModelBackend):
|
|||||||
return
|
return
|
||||||
# Since we can't directly pass other variables to signals, and we want to log the method
|
# Since we can't directly pass other variables to signals, and we want to log the method
|
||||||
# and the token used, we assume we're running in a flow and set a variable in the context
|
# and the token used, we assume we're running in a flow and set a variable in the context
|
||||||
flow_plan: FlowPlan = request.session[SESSION_KEY_PLAN]
|
flow_plan: FlowPlan = request.session.get(SESSION_KEY_PLAN, FlowPlan(""))
|
||||||
flow_plan.context[PLAN_CONTEXT_METHOD] = method
|
flow_plan.context[PLAN_CONTEXT_METHOD] = method
|
||||||
flow_plan.context[PLAN_CONTEXT_METHOD_ARGS] = cleanse_dict(sanitize_dict(kwargs))
|
flow_plan.context[PLAN_CONTEXT_METHOD_ARGS] = cleanse_dict(sanitize_dict(kwargs))
|
||||||
request.session[SESSION_KEY_PLAN] = flow_plan
|
request.session[SESSION_KEY_PLAN] = flow_plan
|
||||||
|
@ -15,7 +15,6 @@ import authentik.lib.models
|
|||||||
|
|
||||||
|
|
||||||
def migrate_sessions(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
def migrate_sessions(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
||||||
db_alias = schema_editor.connection.alias
|
|
||||||
from django.contrib.sessions.backends.cache import KEY_PREFIX
|
from django.contrib.sessions.backends.cache import KEY_PREFIX
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ import authentik.core.models
|
|||||||
|
|
||||||
|
|
||||||
def migrate_sessions(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
def migrate_sessions(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
||||||
db_alias = schema_editor.connection.alias
|
|
||||||
from django.contrib.sessions.backends.cache import KEY_PREFIX
|
from django.contrib.sessions.backends.cache import KEY_PREFIX
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
|
||||||
|
@ -1,19 +1,20 @@
|
|||||||
"""authentik core models"""
|
"""authentik core models"""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from hashlib import md5, sha256
|
from hashlib import md5, sha256
|
||||||
from typing import Any, Optional, Type
|
from typing import Any, Optional
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from deepmerge import always_merger
|
from deepmerge import always_merger
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.contrib.auth.hashers import check_password
|
||||||
from django.contrib.auth.models import AbstractUser
|
from django.contrib.auth.models import AbstractUser
|
||||||
from django.contrib.auth.models import UserManager as DjangoUserManager
|
from django.contrib.auth.models import UserManager as DjangoUserManager
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Q, QuerySet, options
|
from django.db.models import Q, QuerySet, options
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
from django.templatetags.static import static
|
from django.templatetags.static import static
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import SimpleLazyObject, cached_property
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
@ -38,6 +39,7 @@ USER_ATTRIBUTE_SA = "goauthentik.io/user/service-account"
|
|||||||
USER_ATTRIBUTE_SOURCES = "goauthentik.io/user/sources"
|
USER_ATTRIBUTE_SOURCES = "goauthentik.io/user/sources"
|
||||||
USER_ATTRIBUTE_TOKEN_EXPIRING = "goauthentik.io/user/token-expires" # nosec
|
USER_ATTRIBUTE_TOKEN_EXPIRING = "goauthentik.io/user/token-expires" # nosec
|
||||||
USER_ATTRIBUTE_CHANGE_USERNAME = "goauthentik.io/user/can-change-username"
|
USER_ATTRIBUTE_CHANGE_USERNAME = "goauthentik.io/user/can-change-username"
|
||||||
|
USER_ATTRIBUTE_CHANGE_NAME = "goauthentik.io/user/can-change-name"
|
||||||
USER_ATTRIBUTE_CHANGE_EMAIL = "goauthentik.io/user/can-change-email"
|
USER_ATTRIBUTE_CHANGE_EMAIL = "goauthentik.io/user/can-change-email"
|
||||||
USER_ATTRIBUTE_CAN_OVERRIDE_IP = "goauthentik.io/user/override-ips"
|
USER_ATTRIBUTE_CAN_OVERRIDE_IP = "goauthentik.io/user/override-ips"
|
||||||
|
|
||||||
@ -160,6 +162,22 @@ class User(GuardianUserMixin, AbstractUser):
|
|||||||
self.password_change_date = now()
|
self.password_change_date = now()
|
||||||
return super().set_password(password)
|
return super().set_password(password)
|
||||||
|
|
||||||
|
def check_password(self, raw_password: str) -> bool:
|
||||||
|
"""
|
||||||
|
Return a boolean of whether the raw_password was correct. Handles
|
||||||
|
hashing formats behind the scenes.
|
||||||
|
|
||||||
|
Slightly changed version which doesn't send a signal for such internal hash upgrades
|
||||||
|
"""
|
||||||
|
|
||||||
|
def setter(raw_password):
|
||||||
|
self.set_password(raw_password, signal=False)
|
||||||
|
# Password hash upgrades shouldn't be considered password changes.
|
||||||
|
self._password = None
|
||||||
|
self.save(update_fields=["password"])
|
||||||
|
|
||||||
|
return check_password(raw_password, self.password, setter)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def uid(self) -> str:
|
def uid(self) -> str:
|
||||||
"""Generate a globall unique UID, based on the user ID and the hashed secret key"""
|
"""Generate a globall unique UID, based on the user ID and the hashed secret key"""
|
||||||
@ -224,7 +242,7 @@ class Provider(SerializerModel):
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def serializer(self) -> Type[Serializer]:
|
def serializer(self) -> type[Serializer]:
|
||||||
"""Get serializer for this model"""
|
"""Get serializer for this model"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@ -266,13 +284,24 @@ class Application(PolicyBindingModel):
|
|||||||
return self.meta_icon.name
|
return self.meta_icon.name
|
||||||
return self.meta_icon.url
|
return self.meta_icon.url
|
||||||
|
|
||||||
def get_launch_url(self) -> Optional[str]:
|
def get_launch_url(self, user: Optional["User"] = None) -> Optional[str]:
|
||||||
"""Get launch URL if set, otherwise attempt to get launch URL based on provider."""
|
"""Get launch URL if set, otherwise attempt to get launch URL based on provider."""
|
||||||
|
url = None
|
||||||
if self.meta_launch_url:
|
if self.meta_launch_url:
|
||||||
return self.meta_launch_url
|
url = self.meta_launch_url
|
||||||
if provider := self.get_provider():
|
if provider := self.get_provider():
|
||||||
return provider.launch_url
|
url = provider.launch_url
|
||||||
return None
|
if user:
|
||||||
|
if isinstance(user, SimpleLazyObject):
|
||||||
|
user._setup()
|
||||||
|
user = user._wrapped
|
||||||
|
try:
|
||||||
|
return url % user.__dict__
|
||||||
|
# pylint: disable=broad-except
|
||||||
|
except Exception as exc:
|
||||||
|
LOGGER.warning("Failed to format launch url", exc=exc)
|
||||||
|
return url
|
||||||
|
return url
|
||||||
|
|
||||||
def get_provider(self) -> Optional[Provider]:
|
def get_provider(self) -> Optional[Provider]:
|
||||||
"""Get casted provider instance"""
|
"""Get casted provider instance"""
|
||||||
@ -505,7 +534,7 @@ class PropertyMapping(SerializerModel, ManagedModel):
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def serializer(self) -> Type[Serializer]:
|
def serializer(self) -> type[Serializer]:
|
||||||
"""Get serializer for this model"""
|
"""Get serializer for this model"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""authentik core signals"""
|
"""authentik core signals"""
|
||||||
from typing import TYPE_CHECKING, Type
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
from django.apps import apps
|
||||||
from django.contrib.auth.signals import user_logged_in, user_logged_out
|
from django.contrib.auth.signals import user_logged_in, user_logged_out
|
||||||
from django.contrib.sessions.backends.cache import KEY_PREFIX
|
from django.contrib.sessions.backends.cache import KEY_PREFIX
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
@ -11,6 +12,8 @@ from django.dispatch import receiver
|
|||||||
from django.http.request import HttpRequest
|
from django.http.request import HttpRequest
|
||||||
from prometheus_client import Gauge
|
from prometheus_client import Gauge
|
||||||
|
|
||||||
|
from authentik.root.monitoring import monitoring_set
|
||||||
|
|
||||||
# Arguments: user: User, password: str
|
# Arguments: user: User, password: str
|
||||||
password_changed = Signal()
|
password_changed = Signal()
|
||||||
|
|
||||||
@ -20,6 +23,17 @@ if TYPE_CHECKING:
|
|||||||
from authentik.core.models import AuthenticatedSession, User
|
from authentik.core.models import AuthenticatedSession, User
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(monitoring_set)
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def monitoring_set_models(sender, **kwargs):
|
||||||
|
"""set models gauges"""
|
||||||
|
for model in apps.get_models():
|
||||||
|
GAUGE_MODELS.labels(
|
||||||
|
model_name=model._meta.model_name,
|
||||||
|
app=model._meta.app_label,
|
||||||
|
).set(model.objects.count())
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save)
|
@receiver(post_save)
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def post_save_application(sender: type[Model], instance, created: bool, **_):
|
def post_save_application(sender: type[Model], instance, created: bool, **_):
|
||||||
@ -27,11 +41,6 @@ def post_save_application(sender: type[Model], instance, created: bool, **_):
|
|||||||
from authentik.core.api.applications import user_app_cache_key
|
from authentik.core.api.applications import user_app_cache_key
|
||||||
from authentik.core.models import Application
|
from authentik.core.models import Application
|
||||||
|
|
||||||
GAUGE_MODELS.labels(
|
|
||||||
model_name=sender._meta.model_name,
|
|
||||||
app=sender._meta.app_label,
|
|
||||||
).set(sender.objects.count())
|
|
||||||
|
|
||||||
if sender != Application:
|
if sender != Application:
|
||||||
return
|
return
|
||||||
if not created: # pragma: no cover
|
if not created: # pragma: no cover
|
||||||
@ -62,7 +71,7 @@ def user_logged_out_session(sender, request: HttpRequest, user: "User", **_):
|
|||||||
|
|
||||||
|
|
||||||
@receiver(pre_delete)
|
@receiver(pre_delete)
|
||||||
def authenticated_session_delete(sender: Type[Model], instance: "AuthenticatedSession", **_):
|
def authenticated_session_delete(sender: type[Model], instance: "AuthenticatedSession", **_):
|
||||||
"""Delete session when authenticated session is deleted"""
|
"""Delete session when authenticated session is deleted"""
|
||||||
from authentik.core.models import AuthenticatedSession
|
from authentik.core.models import AuthenticatedSession
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Source decision helper"""
|
"""Source decision helper"""
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, Optional, Type
|
from typing import Any, Optional
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
@ -14,6 +14,7 @@ from structlog.stdlib import get_logger
|
|||||||
from authentik.core.models import Source, SourceUserMatchingModes, User, UserSourceConnection
|
from authentik.core.models import Source, SourceUserMatchingModes, User, UserSourceConnection
|
||||||
from authentik.core.sources.stage import PLAN_CONTEXT_SOURCES_CONNECTION, PostUserEnrollmentStage
|
from authentik.core.sources.stage import PLAN_CONTEXT_SOURCES_CONNECTION, PostUserEnrollmentStage
|
||||||
from authentik.events.models import Event, EventAction
|
from authentik.events.models import Event, EventAction
|
||||||
|
from authentik.flows.exceptions import FlowNonApplicableException
|
||||||
from authentik.flows.models import Flow, Stage, in_memory_stage
|
from authentik.flows.models import Flow, Stage, in_memory_stage
|
||||||
from authentik.flows.planner import (
|
from authentik.flows.planner import (
|
||||||
PLAN_CONTEXT_PENDING_USER,
|
PLAN_CONTEXT_PENDING_USER,
|
||||||
@ -24,6 +25,8 @@ from authentik.flows.planner import (
|
|||||||
)
|
)
|
||||||
from authentik.flows.views.executor import NEXT_ARG_NAME, SESSION_KEY_GET, SESSION_KEY_PLAN
|
from authentik.flows.views.executor import NEXT_ARG_NAME, SESSION_KEY_GET, SESSION_KEY_PLAN
|
||||||
from authentik.lib.utils.urls import redirect_with_qs
|
from authentik.lib.utils.urls import redirect_with_qs
|
||||||
|
from authentik.policies.denied import AccessDeniedResponse
|
||||||
|
from authentik.policies.types import PolicyResult
|
||||||
from authentik.policies.utils import delete_none_keys
|
from authentik.policies.utils import delete_none_keys
|
||||||
from authentik.stages.password import BACKEND_INBUILT
|
from authentik.stages.password import BACKEND_INBUILT
|
||||||
from authentik.stages.password.stage import PLAN_CONTEXT_AUTHENTICATION_BACKEND
|
from authentik.stages.password.stage import PLAN_CONTEXT_AUTHENTICATION_BACKEND
|
||||||
@ -50,7 +53,10 @@ class SourceFlowManager:
|
|||||||
|
|
||||||
identifier: str
|
identifier: str
|
||||||
|
|
||||||
connection_type: Type[UserSourceConnection] = UserSourceConnection
|
connection_type: type[UserSourceConnection] = UserSourceConnection
|
||||||
|
|
||||||
|
enroll_info: dict[str, Any]
|
||||||
|
policy_context: dict[str, Any]
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -64,6 +70,7 @@ class SourceFlowManager:
|
|||||||
self.identifier = identifier
|
self.identifier = identifier
|
||||||
self.enroll_info = enroll_info
|
self.enroll_info = enroll_info
|
||||||
self._logger = get_logger().bind(source=source, identifier=identifier)
|
self._logger = get_logger().bind(source=source, identifier=identifier)
|
||||||
|
self.policy_context = {}
|
||||||
|
|
||||||
# pylint: disable=too-many-return-statements
|
# pylint: disable=too-many-return-statements
|
||||||
def get_action(self, **kwargs) -> tuple[Action, Optional[UserSourceConnection]]:
|
def get_action(self, **kwargs) -> tuple[Action, Optional[UserSourceConnection]]:
|
||||||
@ -144,20 +151,23 @@ class SourceFlowManager:
|
|||||||
except IntegrityError as exc:
|
except IntegrityError as exc:
|
||||||
self._logger.warning("failed to get action", exc=exc)
|
self._logger.warning("failed to get action", exc=exc)
|
||||||
return redirect("/")
|
return redirect("/")
|
||||||
self._logger.debug("get_action() says", action=action, connection=connection)
|
self._logger.debug("get_action", action=action, connection=connection)
|
||||||
if connection:
|
try:
|
||||||
if action == Action.LINK:
|
if connection:
|
||||||
self._logger.debug("Linking existing user")
|
if action == Action.LINK:
|
||||||
return self.handle_existing_user_link(connection)
|
self._logger.debug("Linking existing user")
|
||||||
if action == Action.AUTH:
|
return self.handle_existing_user_link(connection)
|
||||||
self._logger.debug("Handling auth user")
|
if action == Action.AUTH:
|
||||||
return self.handle_auth_user(connection)
|
self._logger.debug("Handling auth user")
|
||||||
if action == Action.ENROLL:
|
return self.handle_auth_user(connection)
|
||||||
self._logger.debug("Handling enrollment of new user")
|
if action == Action.ENROLL:
|
||||||
return self.handle_enroll(connection)
|
self._logger.debug("Handling enrollment of new user")
|
||||||
|
return self.handle_enroll(connection)
|
||||||
|
except FlowNonApplicableException as exc:
|
||||||
|
self._logger.warning("Flow non applicable", exc=exc)
|
||||||
|
return self.error_handler(exc, exc.policy_result)
|
||||||
# Default case, assume deny
|
# Default case, assume deny
|
||||||
messages.error(
|
error = (
|
||||||
self.request,
|
|
||||||
_(
|
_(
|
||||||
(
|
(
|
||||||
"Request to authenticate with %(source)s has been denied. Please authenticate "
|
"Request to authenticate with %(source)s has been denied. Please authenticate "
|
||||||
@ -166,7 +176,17 @@ class SourceFlowManager:
|
|||||||
% {"source": self.source.name}
|
% {"source": self.source.name}
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return redirect(reverse("authentik_core:root-redirect"))
|
return self.error_handler(error)
|
||||||
|
|
||||||
|
def error_handler(
|
||||||
|
self, error: Exception, policy_result: Optional[PolicyResult] = None
|
||||||
|
) -> HttpResponse:
|
||||||
|
"""Handle any errors by returning an access denied stage"""
|
||||||
|
response = AccessDeniedResponse(self.request)
|
||||||
|
response.error_message = str(error)
|
||||||
|
if policy_result:
|
||||||
|
response.policy_result = policy_result
|
||||||
|
return response
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def get_stages_to_append(self, flow: Flow) -> list[Stage]:
|
def get_stages_to_append(self, flow: Flow) -> list[Stage]:
|
||||||
@ -179,7 +199,9 @@ class SourceFlowManager:
|
|||||||
]
|
]
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def _handle_login_flow(self, flow: Flow, **kwargs) -> HttpResponse:
|
def _handle_login_flow(
|
||||||
|
self, flow: Flow, connection: UserSourceConnection, **kwargs
|
||||||
|
) -> HttpResponse:
|
||||||
"""Prepare Authentication Plan, redirect user FlowExecutor"""
|
"""Prepare Authentication Plan, redirect user FlowExecutor"""
|
||||||
# Ensure redirect is carried through when user was trying to
|
# Ensure redirect is carried through when user was trying to
|
||||||
# authorize application
|
# authorize application
|
||||||
@ -193,8 +215,10 @@ class SourceFlowManager:
|
|||||||
PLAN_CONTEXT_SSO: True,
|
PLAN_CONTEXT_SSO: True,
|
||||||
PLAN_CONTEXT_SOURCE: self.source,
|
PLAN_CONTEXT_SOURCE: self.source,
|
||||||
PLAN_CONTEXT_REDIRECT: final_redirect,
|
PLAN_CONTEXT_REDIRECT: final_redirect,
|
||||||
|
PLAN_CONTEXT_SOURCES_CONNECTION: connection,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
kwargs.update(self.policy_context)
|
||||||
if not flow:
|
if not flow:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
# We run the Flow planner here so we can pass the Pending user in the context
|
# We run the Flow planner here so we can pass the Pending user in the context
|
||||||
@ -220,7 +244,7 @@ class SourceFlowManager:
|
|||||||
_("Successfully authenticated with %(source)s!" % {"source": self.source.name}),
|
_("Successfully authenticated with %(source)s!" % {"source": self.source.name}),
|
||||||
)
|
)
|
||||||
flow_kwargs = {PLAN_CONTEXT_PENDING_USER: connection.user}
|
flow_kwargs = {PLAN_CONTEXT_PENDING_USER: connection.user}
|
||||||
return self._handle_login_flow(self.source.authentication_flow, **flow_kwargs)
|
return self._handle_login_flow(self.source.authentication_flow, connection, **flow_kwargs)
|
||||||
|
|
||||||
def handle_existing_user_link(
|
def handle_existing_user_link(
|
||||||
self,
|
self,
|
||||||
@ -264,8 +288,8 @@ class SourceFlowManager:
|
|||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
return self._handle_login_flow(
|
return self._handle_login_flow(
|
||||||
self.source.enrollment_flow,
|
self.source.enrollment_flow,
|
||||||
|
connection,
|
||||||
**{
|
**{
|
||||||
PLAN_CONTEXT_PROMPT: delete_none_keys(self.enroll_info),
|
PLAN_CONTEXT_PROMPT: delete_none_keys(self.enroll_info),
|
||||||
PLAN_CONTEXT_SOURCES_CONNECTION: connection,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -1,18 +1,7 @@
|
|||||||
"""authentik core tasks"""
|
"""authentik core tasks"""
|
||||||
from datetime import datetime
|
|
||||||
from io import StringIO
|
|
||||||
from os import environ
|
|
||||||
|
|
||||||
from boto3.exceptions import Boto3Error
|
|
||||||
from botocore.exceptions import BotoCoreError, ClientError
|
|
||||||
from dbbackup.db.exceptions import CommandConnectorError
|
|
||||||
from django.conf import settings
|
|
||||||
from django.contrib.humanize.templatetags.humanize import naturaltime
|
|
||||||
from django.contrib.sessions.backends.cache import KEY_PREFIX
|
from django.contrib.sessions.backends.cache import KEY_PREFIX
|
||||||
from django.core import management
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
from kubernetes.config.incluster_config import SERVICE_HOST_ENV_NAME
|
|
||||||
from structlog.stdlib import get_logger
|
from structlog.stdlib import get_logger
|
||||||
|
|
||||||
from authentik.core.models import AuthenticatedSession, ExpiringModel
|
from authentik.core.models import AuthenticatedSession, ExpiringModel
|
||||||
@ -22,7 +11,6 @@ from authentik.events.monitored_tasks import (
|
|||||||
TaskResultStatus,
|
TaskResultStatus,
|
||||||
prefill_task,
|
prefill_task,
|
||||||
)
|
)
|
||||||
from authentik.lib.config import CONFIG
|
|
||||||
from authentik.root.celery import CELERY_APP
|
from authentik.root.celery import CELERY_APP
|
||||||
|
|
||||||
LOGGER = get_logger()
|
LOGGER = get_logger()
|
||||||
@ -54,48 +42,3 @@ def clean_expired_models(self: MonitoredTask):
|
|||||||
LOGGER.debug("Expired sessions", model=AuthenticatedSession, amount=amount)
|
LOGGER.debug("Expired sessions", model=AuthenticatedSession, amount=amount)
|
||||||
messages.append(f"Expired {amount} {AuthenticatedSession._meta.verbose_name_plural}")
|
messages.append(f"Expired {amount} {AuthenticatedSession._meta.verbose_name_plural}")
|
||||||
self.set_status(TaskResult(TaskResultStatus.SUCCESSFUL, messages))
|
self.set_status(TaskResult(TaskResultStatus.SUCCESSFUL, messages))
|
||||||
|
|
||||||
|
|
||||||
def should_backup() -> bool:
|
|
||||||
"""Check if we should be doing backups"""
|
|
||||||
if SERVICE_HOST_ENV_NAME in environ and not CONFIG.y("postgresql.s3_backup.bucket"):
|
|
||||||
LOGGER.info("Running in k8s and s3 backups are not configured, skipping")
|
|
||||||
return False
|
|
||||||
if not CONFIG.y_bool("postgresql.backup.enabled"):
|
|
||||||
return False
|
|
||||||
if settings.DEBUG:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
@CELERY_APP.task(bind=True, base=MonitoredTask)
|
|
||||||
@prefill_task
|
|
||||||
def backup_database(self: MonitoredTask): # pragma: no cover
|
|
||||||
"""Database backup"""
|
|
||||||
self.result_timeout_hours = 25
|
|
||||||
if not should_backup():
|
|
||||||
self.set_status(TaskResult(TaskResultStatus.UNKNOWN, ["Backups are not configured."]))
|
|
||||||
return
|
|
||||||
try:
|
|
||||||
start = datetime.now()
|
|
||||||
out = StringIO()
|
|
||||||
management.call_command("dbbackup", quiet=True, stdout=out)
|
|
||||||
self.set_status(
|
|
||||||
TaskResult(
|
|
||||||
TaskResultStatus.SUCCESSFUL,
|
|
||||||
[
|
|
||||||
f"Successfully finished database backup {naturaltime(start)} {out.getvalue()}",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
LOGGER.info("Successfully backed up database.")
|
|
||||||
except (
|
|
||||||
IOError,
|
|
||||||
BotoCoreError,
|
|
||||||
ClientError,
|
|
||||||
Boto3Error,
|
|
||||||
PermissionError,
|
|
||||||
CommandConnectorError,
|
|
||||||
ValueError,
|
|
||||||
) as exc:
|
|
||||||
self.set_status(TaskResult(TaskResultStatus.ERROR).with_error(exc))
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
{% block head_before %}
|
{% block head_before %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
<link rel="stylesheet" type="text/css" href="{% static 'dist/authentik.css' %}">
|
<link rel="stylesheet" type="text/css" href="{% static 'dist/authentik.css' %}">
|
||||||
|
<link rel="stylesheet" type="text/css" href="{% static 'dist/custom.css' %}">
|
||||||
<script src="{% static 'dist/poly.js' %}" type="module"></script>
|
<script src="{% static 'dist/poly.js' %}" type="module"></script>
|
||||||
{% block head %}
|
{% block head %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -5,11 +5,13 @@
|
|||||||
|
|
||||||
{% block head %}
|
{% block head %}
|
||||||
<script src="{% static 'dist/admin/AdminInterface.js' %}" type="module"></script>
|
<script src="{% static 'dist/admin/AdminInterface.js' %}" type="module"></script>
|
||||||
|
<meta name="theme-color" content="#18191a" media="(prefers-color-scheme: dark)">
|
||||||
|
<meta name="theme-color" content="#ffffff" media="(prefers-color-scheme: light)">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<ak-message-container></ak-message-container>
|
<ak-message-container data-refresh-on-locale="true"></ak-message-container>
|
||||||
<ak-interface-admin>
|
<ak-interface-admin data-refresh-on-locale="true">
|
||||||
<section class="ak-static-page pf-c-page__main-section pf-m-no-padding-mobile pf-m-xl">
|
<section class="ak-static-page pf-c-page__main-section pf-m-no-padding-mobile pf-m-xl">
|
||||||
<div class="pf-c-empty-state" style="height: 100vh;">
|
<div class="pf-c-empty-state" style="height: 100vh;">
|
||||||
<div class="pf-c-empty-state__content">
|
<div class="pf-c-empty-state__content">
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<ak-message-container></ak-message-container>
|
<ak-message-container data-refresh-on-locale="true"></ak-message-container>
|
||||||
<ak-flow-executor>
|
<ak-flow-executor data-refresh-on-locale="true">
|
||||||
<section class="ak-static-page pf-c-page__main-section pf-m-no-padding-mobile pf-m-xl">
|
<section class="ak-static-page pf-c-page__main-section pf-m-no-padding-mobile pf-m-xl">
|
||||||
<div class="pf-c-empty-state" style="height: 100vh;">
|
<div class="pf-c-empty-state" style="height: 100vh;">
|
||||||
<div class="pf-c-empty-state__content">
|
<div class="pf-c-empty-state__content">
|
||||||
|
@ -5,11 +5,13 @@
|
|||||||
|
|
||||||
{% block head %}
|
{% block head %}
|
||||||
<script src="{% static 'dist/user/UserInterface.js' %}" type="module"></script>
|
<script src="{% static 'dist/user/UserInterface.js' %}" type="module"></script>
|
||||||
|
<meta name="theme-color" content="#151515" media="(prefers-color-scheme: light)">
|
||||||
|
<meta name="theme-color" content="#151515" media="(prefers-color-scheme: dark)">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<ak-message-container></ak-message-container>
|
<ak-message-container data-refresh-on-locale="true"></ak-message-container>
|
||||||
<ak-interface-user>
|
<ak-interface-user data-refresh-on-locale="true">
|
||||||
<section class="ak-static-page pf-c-page__main-section pf-m-no-padding-mobile pf-m-xl">
|
<section class="ak-static-page pf-c-page__main-section pf-m-no-padding-mobile pf-m-xl">
|
||||||
<div class="pf-c-empty-state" style="height: 100vh;">
|
<div class="pf-c-empty-state" style="height: 100vh;">
|
||||||
<div class="pf-c-empty-state__content">
|
<div class="pf-c-empty-state__content">
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
"""Test Applications API"""
|
"""Test Applications API"""
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.encoding import force_str
|
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
|
|
||||||
from authentik.core.models import Application
|
from authentik.core.models import Application
|
||||||
@ -14,7 +13,9 @@ class TestApplicationsAPI(APITestCase):
|
|||||||
|
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
self.user = create_test_admin_user()
|
self.user = create_test_admin_user()
|
||||||
self.allowed = Application.objects.create(name="allowed", slug="allowed")
|
self.allowed = Application.objects.create(
|
||||||
|
name="allowed", slug="allowed", meta_launch_url="https://goauthentik.io/%(username)s"
|
||||||
|
)
|
||||||
self.denied = Application.objects.create(name="denied", slug="denied")
|
self.denied = Application.objects.create(name="denied", slug="denied")
|
||||||
PolicyBinding.objects.create(
|
PolicyBinding.objects.create(
|
||||||
target=self.denied,
|
target=self.denied,
|
||||||
@ -32,7 +33,7 @@ class TestApplicationsAPI(APITestCase):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertJSONEqual(force_str(response.content), {"messages": [], "passing": True})
|
self.assertJSONEqual(response.content.decode(), {"messages": [], "passing": True})
|
||||||
response = self.client.get(
|
response = self.client.get(
|
||||||
reverse(
|
reverse(
|
||||||
"authentik_api:application-check-access",
|
"authentik_api:application-check-access",
|
||||||
@ -40,14 +41,14 @@ class TestApplicationsAPI(APITestCase):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertJSONEqual(force_str(response.content), {"messages": ["dummy"], "passing": False})
|
self.assertJSONEqual(response.content.decode(), {"messages": ["dummy"], "passing": False})
|
||||||
|
|
||||||
def test_list(self):
|
def test_list(self):
|
||||||
"""Test list operation without superuser_full_list"""
|
"""Test list operation without superuser_full_list"""
|
||||||
self.client.force_login(self.user)
|
self.client.force_login(self.user)
|
||||||
response = self.client.get(reverse("authentik_api:application-list"))
|
response = self.client.get(reverse("authentik_api:application-list"))
|
||||||
self.assertJSONEqual(
|
self.assertJSONEqual(
|
||||||
force_str(response.content),
|
response.content.decode(),
|
||||||
{
|
{
|
||||||
"pagination": {
|
"pagination": {
|
||||||
"next": 0,
|
"next": 0,
|
||||||
@ -65,8 +66,8 @@ class TestApplicationsAPI(APITestCase):
|
|||||||
"slug": "allowed",
|
"slug": "allowed",
|
||||||
"provider": None,
|
"provider": None,
|
||||||
"provider_obj": None,
|
"provider_obj": None,
|
||||||
"launch_url": None,
|
"launch_url": f"https://goauthentik.io/{self.user.username}",
|
||||||
"meta_launch_url": "",
|
"meta_launch_url": "https://goauthentik.io/%(username)s",
|
||||||
"meta_icon": None,
|
"meta_icon": None,
|
||||||
"meta_description": "",
|
"meta_description": "",
|
||||||
"meta_publisher": "",
|
"meta_publisher": "",
|
||||||
@ -83,7 +84,7 @@ class TestApplicationsAPI(APITestCase):
|
|||||||
reverse("authentik_api:application-list") + "?superuser_full_list=true"
|
reverse("authentik_api:application-list") + "?superuser_full_list=true"
|
||||||
)
|
)
|
||||||
self.assertJSONEqual(
|
self.assertJSONEqual(
|
||||||
force_str(response.content),
|
response.content.decode(),
|
||||||
{
|
{
|
||||||
"pagination": {
|
"pagination": {
|
||||||
"next": 0,
|
"next": 0,
|
||||||
@ -101,8 +102,8 @@ class TestApplicationsAPI(APITestCase):
|
|||||||
"slug": "allowed",
|
"slug": "allowed",
|
||||||
"provider": None,
|
"provider": None,
|
||||||
"provider_obj": None,
|
"provider_obj": None,
|
||||||
"launch_url": None,
|
"launch_url": f"https://goauthentik.io/{self.user.username}",
|
||||||
"meta_launch_url": "",
|
"meta_launch_url": "https://goauthentik.io/%(username)s",
|
||||||
"meta_icon": None,
|
"meta_icon": None,
|
||||||
"meta_description": "",
|
"meta_description": "",
|
||||||
"meta_publisher": "",
|
"meta_publisher": "",
|
||||||
|
67
authentik/core/tests/test_applications_views.py
Normal file
67
authentik/core/tests/test_applications_views.py
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
"""Test Applications API"""
|
||||||
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from authentik.core.models import Application
|
||||||
|
from authentik.core.tests.utils import create_test_admin_user, create_test_tenant
|
||||||
|
from authentik.flows.models import Flow, FlowDesignation
|
||||||
|
from authentik.flows.tests import FlowTestCase
|
||||||
|
from authentik.tenants.models import Tenant
|
||||||
|
|
||||||
|
|
||||||
|
class TestApplicationsViews(FlowTestCase):
|
||||||
|
"""Test applications Views"""
|
||||||
|
|
||||||
|
def setUp(self) -> None:
|
||||||
|
self.user = create_test_admin_user()
|
||||||
|
self.allowed = Application.objects.create(
|
||||||
|
name="allowed", slug="allowed", meta_launch_url="https://goauthentik.io/%(username)s"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_check_redirect(self):
|
||||||
|
"""Test redirect"""
|
||||||
|
empty_flow = Flow.objects.create(
|
||||||
|
name="foo",
|
||||||
|
slug="foo",
|
||||||
|
designation=FlowDesignation.AUTHENTICATION,
|
||||||
|
)
|
||||||
|
tenant: Tenant = create_test_tenant()
|
||||||
|
tenant.flow_authentication = empty_flow
|
||||||
|
tenant.save()
|
||||||
|
response = self.client.get(
|
||||||
|
reverse(
|
||||||
|
"authentik_core:application-launch",
|
||||||
|
kwargs={"application_slug": self.allowed.slug},
|
||||||
|
),
|
||||||
|
follow=True,
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
with patch(
|
||||||
|
"authentik.flows.stage.StageView.get_pending_user", MagicMock(return_value=self.user)
|
||||||
|
):
|
||||||
|
response = self.client.post(
|
||||||
|
reverse("authentik_api:flow-executor", kwargs={"flow_slug": empty_flow.slug})
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertStageRedirects(response, f"https://goauthentik.io/{self.user.username}")
|
||||||
|
|
||||||
|
def test_check_redirect_auth(self):
|
||||||
|
"""Test redirect"""
|
||||||
|
self.client.force_login(self.user)
|
||||||
|
empty_flow = Flow.objects.create(
|
||||||
|
name="foo",
|
||||||
|
slug="foo",
|
||||||
|
designation=FlowDesignation.AUTHENTICATION,
|
||||||
|
)
|
||||||
|
tenant: Tenant = create_test_tenant()
|
||||||
|
tenant.flow_authentication = empty_flow
|
||||||
|
tenant.save()
|
||||||
|
response = self.client.get(
|
||||||
|
reverse(
|
||||||
|
"authentik_core:application-launch",
|
||||||
|
kwargs={"application_slug": self.allowed.slug},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 302)
|
||||||
|
self.assertEqual(response.url, f"https://goauthentik.io/{self.user.username}")
|
@ -2,7 +2,6 @@
|
|||||||
from json import loads
|
from json import loads
|
||||||
|
|
||||||
from django.urls.base import reverse
|
from django.urls.base import reverse
|
||||||
from django.utils.encoding import force_str
|
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
|
|
||||||
from authentik.core.models import User
|
from authentik.core.models import User
|
||||||
@ -28,5 +27,5 @@ class TestAuthenticatedSessionsAPI(APITestCase):
|
|||||||
self.client.force_login(self.other_user)
|
self.client.force_login(self.other_user)
|
||||||
response = self.client.get(reverse("authentik_api:authenticatedsession-list"))
|
response = self.client.get(reverse("authentik_api:authenticatedsession-list"))
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
body = loads(force_str(response.content))
|
body = loads(response.content.decode())
|
||||||
self.assertEqual(body["pagination"]["count"], 1)
|
self.assertEqual(body["pagination"]["count"], 1)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""authentik core models tests"""
|
"""authentik core models tests"""
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from typing import Callable, Type
|
from typing import Callable
|
||||||
|
|
||||||
from django.test import RequestFactory, TestCase
|
from django.test import RequestFactory, TestCase
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
@ -27,7 +27,7 @@ class TestModels(TestCase):
|
|||||||
self.assertFalse(token.is_expired)
|
self.assertFalse(token.is_expired)
|
||||||
|
|
||||||
|
|
||||||
def source_tester_factory(test_model: Type[Stage]) -> Callable:
|
def source_tester_factory(test_model: type[Stage]) -> Callable:
|
||||||
"""Test source"""
|
"""Test source"""
|
||||||
|
|
||||||
factory = RequestFactory()
|
factory = RequestFactory()
|
||||||
@ -47,7 +47,7 @@ def source_tester_factory(test_model: Type[Stage]) -> Callable:
|
|||||||
return tester
|
return tester
|
||||||
|
|
||||||
|
|
||||||
def provider_tester_factory(test_model: Type[Stage]) -> Callable:
|
def provider_tester_factory(test_model: type[Stage]) -> Callable:
|
||||||
"""Test provider"""
|
"""Test provider"""
|
||||||
|
|
||||||
def tester(self: TestModels):
|
def tester(self: TestModels):
|
||||||
|
@ -6,8 +6,12 @@ from guardian.utils import get_anonymous_user
|
|||||||
|
|
||||||
from authentik.core.models import SourceUserMatchingModes, User
|
from authentik.core.models import SourceUserMatchingModes, User
|
||||||
from authentik.core.sources.flow_manager import Action
|
from authentik.core.sources.flow_manager import Action
|
||||||
|
from authentik.flows.models import Flow, FlowDesignation
|
||||||
from authentik.lib.generators import generate_id
|
from authentik.lib.generators import generate_id
|
||||||
from authentik.lib.tests.utils import get_request
|
from authentik.lib.tests.utils import get_request
|
||||||
|
from authentik.policies.denied import AccessDeniedResponse
|
||||||
|
from authentik.policies.expression.models import ExpressionPolicy
|
||||||
|
from authentik.policies.models import PolicyBinding
|
||||||
from authentik.sources.oauth.models import OAuthSource, UserOAuthSourceConnection
|
from authentik.sources.oauth.models import OAuthSource, UserOAuthSourceConnection
|
||||||
from authentik.sources.oauth.views.callback import OAuthSourceFlowManager
|
from authentik.sources.oauth.views.callback import OAuthSourceFlowManager
|
||||||
|
|
||||||
@ -17,7 +21,7 @@ class TestSourceFlowManager(TestCase):
|
|||||||
|
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.source = OAuthSource.objects.create(name="test")
|
self.source: OAuthSource = OAuthSource.objects.create(name="test")
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.identifier = generate_id()
|
self.identifier = generate_id()
|
||||||
|
|
||||||
@ -143,3 +147,34 @@ class TestSourceFlowManager(TestCase):
|
|||||||
action, _ = flow_manager.get_action()
|
action, _ = flow_manager.get_action()
|
||||||
self.assertEqual(action, Action.ENROLL)
|
self.assertEqual(action, Action.ENROLL)
|
||||||
flow_manager.get_flow()
|
flow_manager.get_flow()
|
||||||
|
|
||||||
|
def test_error_non_applicable_flow(self):
|
||||||
|
"""Test error handling when a source selected flow is non-applicable due to a policy"""
|
||||||
|
self.source.user_matching_mode = SourceUserMatchingModes.USERNAME_LINK
|
||||||
|
|
||||||
|
flow = Flow.objects.create(
|
||||||
|
name="test", slug="test", title="test", designation=FlowDesignation.ENROLLMENT
|
||||||
|
)
|
||||||
|
policy = ExpressionPolicy.objects.create(
|
||||||
|
name="false", expression="""ak_message("foo");return False"""
|
||||||
|
)
|
||||||
|
PolicyBinding.objects.create(
|
||||||
|
policy=policy,
|
||||||
|
target=flow,
|
||||||
|
order=0,
|
||||||
|
)
|
||||||
|
self.source.enrollment_flow = flow
|
||||||
|
self.source.save()
|
||||||
|
|
||||||
|
flow_manager = OAuthSourceFlowManager(
|
||||||
|
self.source,
|
||||||
|
get_request("/", user=AnonymousUser()),
|
||||||
|
self.identifier,
|
||||||
|
{"username": "foo"},
|
||||||
|
)
|
||||||
|
action, _ = flow_manager.get_action()
|
||||||
|
self.assertEqual(action, Action.ENROLL)
|
||||||
|
response = flow_manager.get_flow()
|
||||||
|
self.assertIsInstance(response, AccessDeniedResponse)
|
||||||
|
# pylint: disable=no-member
|
||||||
|
self.assertEqual(response.error_message, "foo")
|
||||||
|
@ -30,6 +30,7 @@ class TestTokenAPI(APITestCase):
|
|||||||
self.assertEqual(token.user, self.user)
|
self.assertEqual(token.user, self.user)
|
||||||
self.assertEqual(token.intent, TokenIntents.INTENT_API)
|
self.assertEqual(token.intent, TokenIntents.INTENT_API)
|
||||||
self.assertEqual(token.expiring, True)
|
self.assertEqual(token.expiring, True)
|
||||||
|
self.assertTrue(self.user.has_perm("authentik_core.view_token_key", token))
|
||||||
|
|
||||||
def test_token_create_invalid(self):
|
def test_token_create_invalid(self):
|
||||||
"""Test token creation endpoint (invalid data)"""
|
"""Test token creation endpoint (invalid data)"""
|
||||||
|
@ -2,9 +2,10 @@
|
|||||||
from django.urls.base import reverse
|
from django.urls.base import reverse
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
|
|
||||||
from authentik.core.models import USER_ATTRIBUTE_CHANGE_EMAIL, USER_ATTRIBUTE_CHANGE_USERNAME, User
|
from authentik.core.models import User
|
||||||
from authentik.core.tests.utils import create_test_admin_user, create_test_flow, create_test_tenant
|
from authentik.core.tests.utils import create_test_admin_user, create_test_flow, create_test_tenant
|
||||||
from authentik.flows.models import FlowDesignation
|
from authentik.flows.models import FlowDesignation
|
||||||
|
from authentik.lib.generators import generate_key
|
||||||
from authentik.stages.email.models import EmailStage
|
from authentik.stages.email.models import EmailStage
|
||||||
from authentik.tenants.models import Tenant
|
from authentik.tenants.models import Tenant
|
||||||
|
|
||||||
@ -16,34 +17,6 @@ class TestUsersAPI(APITestCase):
|
|||||||
self.admin = create_test_admin_user()
|
self.admin = create_test_admin_user()
|
||||||
self.user = User.objects.create(username="test-user")
|
self.user = User.objects.create(username="test-user")
|
||||||
|
|
||||||
def test_update_self(self):
|
|
||||||
"""Test update_self"""
|
|
||||||
self.client.force_login(self.admin)
|
|
||||||
response = self.client.put(
|
|
||||||
reverse("authentik_api:user-update-self"), data={"username": "foo", "name": "foo"}
|
|
||||||
)
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
def test_update_self_username_denied(self):
|
|
||||||
"""Test update_self"""
|
|
||||||
self.admin.attributes[USER_ATTRIBUTE_CHANGE_USERNAME] = False
|
|
||||||
self.admin.save()
|
|
||||||
self.client.force_login(self.admin)
|
|
||||||
response = self.client.put(
|
|
||||||
reverse("authentik_api:user-update-self"), data={"username": "foo", "name": "foo"}
|
|
||||||
)
|
|
||||||
self.assertEqual(response.status_code, 400)
|
|
||||||
|
|
||||||
def test_update_self_email_denied(self):
|
|
||||||
"""Test update_self"""
|
|
||||||
self.admin.attributes[USER_ATTRIBUTE_CHANGE_EMAIL] = False
|
|
||||||
self.admin.save()
|
|
||||||
self.client.force_login(self.admin)
|
|
||||||
response = self.client.put(
|
|
||||||
reverse("authentik_api:user-update-self"), data={"email": "foo", "name": "foo"}
|
|
||||||
)
|
|
||||||
self.assertEqual(response.status_code, 400)
|
|
||||||
|
|
||||||
def test_metrics(self):
|
def test_metrics(self):
|
||||||
"""Test user's metrics"""
|
"""Test user's metrics"""
|
||||||
self.client.force_login(self.admin)
|
self.client.force_login(self.admin)
|
||||||
@ -68,6 +41,18 @@ class TestUsersAPI(APITestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 404)
|
self.assertEqual(response.status_code, 404)
|
||||||
|
|
||||||
|
def test_set_password(self):
|
||||||
|
"""Test Direct password set"""
|
||||||
|
self.client.force_login(self.admin)
|
||||||
|
new_pw = generate_key()
|
||||||
|
response = self.client.post(
|
||||||
|
reverse("authentik_api:user-set-password", kwargs={"pk": self.admin.pk}),
|
||||||
|
data={"password": new_pw},
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 204)
|
||||||
|
self.admin.refresh_from_db()
|
||||||
|
self.assertTrue(self.admin.check_password(new_pw))
|
||||||
|
|
||||||
def test_recovery(self):
|
def test_recovery(self):
|
||||||
"""Test user recovery link (no recovery flow set)"""
|
"""Test user recovery link (no recovery flow set)"""
|
||||||
flow = create_test_flow(FlowDesignation.RECOVERY)
|
flow = create_test_flow(FlowDesignation.RECOVERY)
|
||||||
|
@ -29,3 +29,4 @@ class UserSettingSerializer(PassiveSerializer):
|
|||||||
component = CharField()
|
component = CharField()
|
||||||
title = CharField()
|
title = CharField()
|
||||||
configure_url = CharField(required=False)
|
configure_url = CharField(required=False)
|
||||||
|
icon_url = CharField(required=False)
|
||||||
|
@ -5,7 +5,7 @@ from django.views.decorators.csrf import ensure_csrf_cookie
|
|||||||
from django.views.generic import RedirectView
|
from django.views.generic import RedirectView
|
||||||
from django.views.generic.base import TemplateView
|
from django.views.generic.base import TemplateView
|
||||||
|
|
||||||
from authentik.core.views import impersonate
|
from authentik.core.views import apps, impersonate
|
||||||
from authentik.core.views.interface import FlowInterfaceView
|
from authentik.core.views.interface import FlowInterfaceView
|
||||||
from authentik.core.views.session import EndSessionView
|
from authentik.core.views.session import EndSessionView
|
||||||
|
|
||||||
@ -15,6 +15,12 @@ urlpatterns = [
|
|||||||
login_required(RedirectView.as_view(pattern_name="authentik_core:if-user")),
|
login_required(RedirectView.as_view(pattern_name="authentik_core:if-user")),
|
||||||
name="root-redirect",
|
name="root-redirect",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
# We have to use this format since everything else uses applications/o or applications/saml
|
||||||
|
"application/launch/<slug:application_slug>/",
|
||||||
|
apps.RedirectToAppLaunch.as_view(),
|
||||||
|
name="application-launch",
|
||||||
|
),
|
||||||
# Impersonation
|
# Impersonation
|
||||||
path(
|
path(
|
||||||
"-/impersonation/<int:user_id>/",
|
"-/impersonation/<int:user_id>/",
|
||||||
|
75
authentik/core/views/apps.py
Normal file
75
authentik/core/views/apps.py
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
"""app views"""
|
||||||
|
from django.http import Http404, HttpRequest, HttpResponse, HttpResponseRedirect
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from django.views import View
|
||||||
|
|
||||||
|
from authentik.core.models import Application
|
||||||
|
from authentik.flows.challenge import (
|
||||||
|
ChallengeResponse,
|
||||||
|
ChallengeTypes,
|
||||||
|
HttpChallengeResponse,
|
||||||
|
RedirectChallenge,
|
||||||
|
)
|
||||||
|
from authentik.flows.models import in_memory_stage
|
||||||
|
from authentik.flows.planner import PLAN_CONTEXT_APPLICATION, FlowPlanner
|
||||||
|
from authentik.flows.stage import ChallengeStageView
|
||||||
|
from authentik.flows.views.executor import SESSION_KEY_PLAN
|
||||||
|
from authentik.lib.utils.urls import redirect_with_qs
|
||||||
|
from authentik.stages.consent.stage import (
|
||||||
|
PLAN_CONTEXT_CONSENT_HEADER,
|
||||||
|
PLAN_CONTEXT_CONSENT_PERMISSIONS,
|
||||||
|
)
|
||||||
|
from authentik.tenants.models import Tenant
|
||||||
|
|
||||||
|
|
||||||
|
class RedirectToAppLaunch(View):
|
||||||
|
"""Application launch view, redirect to the launch URL"""
|
||||||
|
|
||||||
|
def dispatch(self, request: HttpRequest, application_slug: str) -> HttpResponse:
|
||||||
|
app = get_object_or_404(Application, slug=application_slug)
|
||||||
|
# Check here if the application has any launch URL set, if not 404
|
||||||
|
launch = app.get_launch_url()
|
||||||
|
if not launch:
|
||||||
|
raise Http404
|
||||||
|
# Check if we're authenticated already, saves us the flow run
|
||||||
|
if request.user.is_authenticated:
|
||||||
|
return HttpResponseRedirect(app.get_launch_url(request.user))
|
||||||
|
# otherwise, do a custom flow plan that includes the application that's
|
||||||
|
# being accessed, to improve usability
|
||||||
|
tenant: Tenant = request.tenant
|
||||||
|
flow = tenant.flow_authentication
|
||||||
|
planner = FlowPlanner(flow)
|
||||||
|
planner.allow_empty_flows = True
|
||||||
|
plan = planner.plan(
|
||||||
|
request,
|
||||||
|
{
|
||||||
|
PLAN_CONTEXT_APPLICATION: app,
|
||||||
|
PLAN_CONTEXT_CONSENT_HEADER: _("You're about to sign into %(application)s.")
|
||||||
|
% {"application": app.name},
|
||||||
|
PLAN_CONTEXT_CONSENT_PERMISSIONS: [],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
plan.insert_stage(in_memory_stage(RedirectToAppStage))
|
||||||
|
request.session[SESSION_KEY_PLAN] = plan
|
||||||
|
return redirect_with_qs("authentik_core:if-flow", request.GET, flow_slug=flow.slug)
|
||||||
|
|
||||||
|
|
||||||
|
class RedirectToAppStage(ChallengeStageView):
|
||||||
|
"""Final stage to be inserted after the user logs in"""
|
||||||
|
|
||||||
|
def get_challenge(self, *args, **kwargs) -> RedirectChallenge:
|
||||||
|
app = self.executor.plan.context[PLAN_CONTEXT_APPLICATION]
|
||||||
|
launch = app.get_launch_url(self.get_pending_user())
|
||||||
|
# sanity check to ensure launch is still set
|
||||||
|
if not launch:
|
||||||
|
raise Http404
|
||||||
|
return RedirectChallenge(
|
||||||
|
instance={
|
||||||
|
"type": ChallengeTypes.REDIRECT.value,
|
||||||
|
"to": launch,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
def challenge_valid(self, response: ChallengeResponse) -> HttpResponse:
|
||||||
|
return HttpChallengeResponse(self.get_challenge())
|
@ -1,4 +1,6 @@
|
|||||||
"""Crypto API Views"""
|
"""Crypto API Views"""
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
from cryptography.hazmat.primitives.serialization import load_pem_private_key
|
from cryptography.hazmat.primitives.serialization import load_pem_private_key
|
||||||
from cryptography.x509 import load_pem_x509_certificate
|
from cryptography.x509 import load_pem_x509_certificate
|
||||||
@ -15,6 +17,7 @@ from rest_framework.request import Request
|
|||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.serializers import ModelSerializer, ValidationError
|
from rest_framework.serializers import ModelSerializer, ValidationError
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
from structlog.stdlib import get_logger
|
||||||
|
|
||||||
from authentik.api.decorators import permission_required
|
from authentik.api.decorators import permission_required
|
||||||
from authentik.core.api.used_by import UsedByMixin
|
from authentik.core.api.used_by import UsedByMixin
|
||||||
@ -24,6 +27,8 @@ from authentik.crypto.managed import MANAGED_KEY
|
|||||||
from authentik.crypto.models import CertificateKeyPair
|
from authentik.crypto.models import CertificateKeyPair
|
||||||
from authentik.events.models import Event, EventAction
|
from authentik.events.models import Event, EventAction
|
||||||
|
|
||||||
|
LOGGER = get_logger()
|
||||||
|
|
||||||
|
|
||||||
class CertificateKeyPairSerializer(ModelSerializer):
|
class CertificateKeyPairSerializer(ModelSerializer):
|
||||||
"""CertificateKeyPair Serializer"""
|
"""CertificateKeyPair Serializer"""
|
||||||
@ -31,6 +36,7 @@ class CertificateKeyPairSerializer(ModelSerializer):
|
|||||||
cert_expiry = DateTimeField(source="certificate.not_valid_after", read_only=True)
|
cert_expiry = DateTimeField(source="certificate.not_valid_after", read_only=True)
|
||||||
cert_subject = SerializerMethodField()
|
cert_subject = SerializerMethodField()
|
||||||
private_key_available = SerializerMethodField()
|
private_key_available = SerializerMethodField()
|
||||||
|
private_key_type = SerializerMethodField()
|
||||||
|
|
||||||
certificate_download_url = SerializerMethodField()
|
certificate_download_url = SerializerMethodField()
|
||||||
private_key_download_url = SerializerMethodField()
|
private_key_download_url = SerializerMethodField()
|
||||||
@ -43,6 +49,13 @@ class CertificateKeyPairSerializer(ModelSerializer):
|
|||||||
"""Show if this keypair has a private key configured or not"""
|
"""Show if this keypair has a private key configured or not"""
|
||||||
return instance.key_data != "" and instance.key_data is not None
|
return instance.key_data != "" and instance.key_data is not None
|
||||||
|
|
||||||
|
def get_private_key_type(self, instance: CertificateKeyPair) -> Optional[str]:
|
||||||
|
"""Get the private key's type, if set"""
|
||||||
|
key = instance.private_key
|
||||||
|
if key:
|
||||||
|
return key.__class__.__name__.replace("_", "").lower().replace("privatekey", "")
|
||||||
|
return None
|
||||||
|
|
||||||
def get_certificate_download_url(self, instance: CertificateKeyPair) -> str:
|
def get_certificate_download_url(self, instance: CertificateKeyPair) -> str:
|
||||||
"""Get URL to download certificate"""
|
"""Get URL to download certificate"""
|
||||||
return (
|
return (
|
||||||
@ -66,8 +79,11 @@ class CertificateKeyPairSerializer(ModelSerializer):
|
|||||||
def validate_certificate_data(self, value: str) -> str:
|
def validate_certificate_data(self, value: str) -> str:
|
||||||
"""Verify that input is a valid PEM x509 Certificate"""
|
"""Verify that input is a valid PEM x509 Certificate"""
|
||||||
try:
|
try:
|
||||||
load_pem_x509_certificate(value.encode("utf-8"), default_backend())
|
# Cast to string to fully load and parse certificate
|
||||||
except ValueError:
|
# Prevents issues like https://github.com/goauthentik/authentik/issues/2082
|
||||||
|
str(load_pem_x509_certificate(value.encode("utf-8"), default_backend()))
|
||||||
|
except ValueError as exc:
|
||||||
|
LOGGER.warning("Failed to load certificate", exc=exc)
|
||||||
raise ValidationError("Unable to load certificate.")
|
raise ValidationError("Unable to load certificate.")
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@ -76,12 +92,17 @@ class CertificateKeyPairSerializer(ModelSerializer):
|
|||||||
# Since this field is optional, data can be empty.
|
# Since this field is optional, data can be empty.
|
||||||
if value != "":
|
if value != "":
|
||||||
try:
|
try:
|
||||||
load_pem_private_key(
|
# Cast to string to fully load and parse certificate
|
||||||
str.encode("\n".join([x.strip() for x in value.split("\n")])),
|
# Prevents issues like https://github.com/goauthentik/authentik/issues/2082
|
||||||
password=None,
|
str(
|
||||||
backend=default_backend(),
|
load_pem_private_key(
|
||||||
|
str.encode("\n".join([x.strip() for x in value.split("\n")])),
|
||||||
|
password=None,
|
||||||
|
backend=default_backend(),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError) as exc:
|
||||||
|
LOGGER.warning("Failed to load private key", exc=exc)
|
||||||
raise ValidationError("Unable to load private key (possibly encrypted?).")
|
raise ValidationError("Unable to load private key (possibly encrypted?).")
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@ -98,6 +119,7 @@ class CertificateKeyPairSerializer(ModelSerializer):
|
|||||||
"cert_expiry",
|
"cert_expiry",
|
||||||
"cert_subject",
|
"cert_subject",
|
||||||
"private_key_available",
|
"private_key_available",
|
||||||
|
"private_key_type",
|
||||||
"certificate_download_url",
|
"certificate_download_url",
|
||||||
"private_key_download_url",
|
"private_key_download_url",
|
||||||
"managed",
|
"managed",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""authentik crypto models"""
|
"""authentik crypto models"""
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
from typing import Optional, Union
|
from typing import Optional
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
@ -41,8 +41,8 @@ class CertificateKeyPair(ManagedModel, CreatedUpdatedModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
_cert: Optional[Certificate] = None
|
_cert: Optional[Certificate] = None
|
||||||
_private_key: Optional[Union[RSAPrivateKey, EllipticCurvePrivateKey, Ed25519PrivateKey]] = None
|
_private_key: Optional[RSAPrivateKey | EllipticCurvePrivateKey | Ed25519PrivateKey] = None
|
||||||
_public_key: Optional[Union[RSAPublicKey, EllipticCurvePublicKey, Ed25519PublicKey]] = None
|
_public_key: Optional[RSAPublicKey | EllipticCurvePublicKey | Ed25519PublicKey] = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def certificate(self) -> Certificate:
|
def certificate(self) -> Certificate:
|
||||||
@ -54,7 +54,7 @@ class CertificateKeyPair(ManagedModel, CreatedUpdatedModel):
|
|||||||
return self._cert
|
return self._cert
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def public_key(self) -> Optional[Union[RSAPublicKey, EllipticCurvePublicKey, Ed25519PublicKey]]:
|
def public_key(self) -> Optional[RSAPublicKey | EllipticCurvePublicKey | Ed25519PublicKey]:
|
||||||
"""Get public key of the private key"""
|
"""Get public key of the private key"""
|
||||||
if not self._public_key:
|
if not self._public_key:
|
||||||
self._public_key = self.private_key.public_key()
|
self._public_key = self.private_key.public_key()
|
||||||
@ -63,7 +63,7 @@ class CertificateKeyPair(ManagedModel, CreatedUpdatedModel):
|
|||||||
@property
|
@property
|
||||||
def private_key(
|
def private_key(
|
||||||
self,
|
self,
|
||||||
) -> Optional[Union[RSAPrivateKey, EllipticCurvePrivateKey, Ed25519PrivateKey]]:
|
) -> Optional[RSAPrivateKey | EllipticCurvePrivateKey | Ed25519PrivateKey]:
|
||||||
"""Get python cryptography PrivateKey instance"""
|
"""Get python cryptography PrivateKey instance"""
|
||||||
if not self._private_key and self.key_data != "":
|
if not self._private_key and self.key_data != "":
|
||||||
try:
|
try:
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
"""events GeoIP Reader"""
|
"""events GeoIP Reader"""
|
||||||
from datetime import datetime
|
|
||||||
from os import stat
|
from os import stat
|
||||||
from time import time
|
|
||||||
from typing import Optional, TypedDict
|
from typing import Optional, TypedDict
|
||||||
|
|
||||||
from geoip2.database import Reader
|
from geoip2.database import Reader
|
||||||
@ -35,26 +33,29 @@ class GeoIPReader:
|
|||||||
|
|
||||||
def __open(self):
|
def __open(self):
|
||||||
"""Get GeoIP Reader, if configured, otherwise none"""
|
"""Get GeoIP Reader, if configured, otherwise none"""
|
||||||
path = CONFIG.y("authentik.geoip")
|
path = CONFIG.y("geoip")
|
||||||
if path == "" or not path:
|
if path == "" or not path:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
reader = Reader(path)
|
self.__reader = Reader(path)
|
||||||
self.__reader = reader
|
|
||||||
self.__last_mtime = stat(path).st_mtime
|
self.__last_mtime = stat(path).st_mtime
|
||||||
LOGGER.info("Loaded GeoIP database", last_write=self.__last_mtime)
|
LOGGER.info("Loaded GeoIP database", last_write=self.__last_mtime)
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
LOGGER.warning("Failed to load GeoIP database", exc=exc)
|
LOGGER.warning("Failed to load GeoIP database", exc=exc)
|
||||||
|
|
||||||
def __check_expired(self):
|
def __check_expired(self):
|
||||||
"""Check if the geoip database has been opened longer than 8 hours,
|
"""Check if the modification date of the GeoIP database has
|
||||||
and re-open it, as it will probably will have been re-downloaded"""
|
changed, and reload it if so"""
|
||||||
now = time()
|
path = CONFIG.y("geoip")
|
||||||
diff = datetime.fromtimestamp(now) - datetime.fromtimestamp(self.__last_mtime)
|
try:
|
||||||
diff_hours = diff.total_seconds() // 3600
|
mtime = stat(path).st_mtime
|
||||||
if diff_hours >= 8:
|
diff = self.__last_mtime < mtime
|
||||||
LOGGER.info("GeoIP databased loaded too long, re-opening", diff=diff)
|
if diff > 0:
|
||||||
self.__open()
|
LOGGER.info("Found new GeoIP Database, reopening", diff=diff)
|
||||||
|
self.__open()
|
||||||
|
except OSError as exc:
|
||||||
|
LOGGER.warning("Failed to check GeoIP age", exc=exc)
|
||||||
|
return
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def enabled(self) -> bool:
|
def enabled(self) -> bool:
|
||||||
|
@ -19,7 +19,7 @@ def convert_user_to_json(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
|||||||
Event = apps.get_model("authentik_events", "Event")
|
Event = apps.get_model("authentik_events", "Event")
|
||||||
|
|
||||||
db_alias = schema_editor.connection.alias
|
db_alias = schema_editor.connection.alias
|
||||||
for event in Event.objects.all():
|
for event in Event.objects.using(db_alias).all():
|
||||||
event.delete()
|
event.delete()
|
||||||
# Because event objects cannot be updated, we have to re-create them
|
# Because event objects cannot be updated, we have to re-create them
|
||||||
event.pk = None
|
event.pk = None
|
||||||
|
@ -10,7 +10,7 @@ def convert_user_to_json(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
|||||||
Event = apps.get_model("authentik_events", "Event")
|
Event = apps.get_model("authentik_events", "Event")
|
||||||
|
|
||||||
db_alias = schema_editor.connection.alias
|
db_alias = schema_editor.connection.alias
|
||||||
for event in Event.objects.all():
|
for event in Event.objects.using(db_alias).all():
|
||||||
event.delete()
|
event.delete()
|
||||||
# Because event objects cannot be updated, we have to re-create them
|
# Because event objects cannot be updated, we have to re-create them
|
||||||
event.pk = None
|
event.pk = None
|
||||||
|
@ -4,7 +4,7 @@ from collections import Counter
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from inspect import currentframe
|
from inspect import currentframe
|
||||||
from smtplib import SMTPException
|
from smtplib import SMTPException
|
||||||
from typing import TYPE_CHECKING, Optional, Type, Union
|
from typing import TYPE_CHECKING, Optional
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -190,7 +190,7 @@ class Event(ExpiringModel):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def new(
|
def new(
|
||||||
action: Union[str, EventAction],
|
action: str | EventAction,
|
||||||
app: Optional[str] = None,
|
app: Optional[str] = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> "Event":
|
) -> "Event":
|
||||||
@ -517,7 +517,7 @@ class NotificationWebhookMapping(PropertyMapping):
|
|||||||
return "ak-property-mapping-notification-form"
|
return "ak-property-mapping-notification-form"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def serializer(self) -> Type["Serializer"]:
|
def serializer(self) -> type["Serializer"]:
|
||||||
from authentik.events.api.notification_mapping import NotificationWebhookMappingSerializer
|
from authentik.events.api.notification_mapping import NotificationWebhookMappingSerializer
|
||||||
|
|
||||||
return NotificationWebhookMappingSerializer
|
return NotificationWebhookMappingSerializer
|
||||||
|
@ -72,7 +72,7 @@ class WithUserInfoChallenge(Challenge):
|
|||||||
pending_user_avatar = CharField()
|
pending_user_avatar = CharField()
|
||||||
|
|
||||||
|
|
||||||
class AccessDeniedChallenge(Challenge):
|
class AccessDeniedChallenge(WithUserInfoChallenge):
|
||||||
"""Challenge when a flow's active stage calls `stage_invalid()`."""
|
"""Challenge when a flow's active stage calls `stage_invalid()`."""
|
||||||
|
|
||||||
error_message = CharField(required=False)
|
error_message = CharField(required=False)
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
"""flow exceptions"""
|
"""flow exceptions"""
|
||||||
|
|
||||||
from authentik.lib.sentry import SentryIgnoredException
|
from authentik.lib.sentry import SentryIgnoredException
|
||||||
|
from authentik.policies.types import PolicyResult
|
||||||
|
|
||||||
|
|
||||||
class FlowNonApplicableException(SentryIgnoredException):
|
class FlowNonApplicableException(SentryIgnoredException):
|
||||||
"""Flow does not apply to current user (denied by policy)."""
|
"""Flow does not apply to current user (denied by policy)."""
|
||||||
|
|
||||||
|
policy_result: PolicyResult
|
||||||
|
|
||||||
|
|
||||||
class EmptyFlowException(SentryIgnoredException):
|
class EmptyFlowException(SentryIgnoredException):
|
||||||
"""Flow has no stages."""
|
"""Flow has no stages."""
|
||||||
|
@ -10,8 +10,8 @@ def add_title_for_defaults(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
|||||||
"default-invalidation-flow": "Default Invalidation Flow",
|
"default-invalidation-flow": "Default Invalidation Flow",
|
||||||
"default-source-enrollment": "Welcome to authentik! Please select a username.",
|
"default-source-enrollment": "Welcome to authentik! Please select a username.",
|
||||||
"default-source-authentication": "Welcome to authentik!",
|
"default-source-authentication": "Welcome to authentik!",
|
||||||
"default-provider-authorization-implicit-consent": "Default Provider Authorization Flow (implicit consent)",
|
"default-provider-authorization-implicit-consent": "Redirecting to %(app)s",
|
||||||
"default-provider-authorization-explicit-consent": "Default Provider Authorization Flow (explicit consent)",
|
"default-provider-authorization-explicit-consent": "Redirecting to %(app)s",
|
||||||
"default-password-change": "Change password",
|
"default-password-change": "Change password",
|
||||||
}
|
}
|
||||||
db_alias = schema_editor.connection.alias
|
db_alias = schema_editor.connection.alias
|
||||||
|
27
authentik/flows/migrations/0021_auto_20211227_2103.py
Normal file
27
authentik/flows/migrations/0021_auto_20211227_2103.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# Generated by Django 4.0 on 2021-12-27 21:03
|
||||||
|
from django.apps.registry import Apps
|
||||||
|
from django.db import migrations, models
|
||||||
|
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
||||||
|
|
||||||
|
|
||||||
|
def update_title_for_defaults(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
||||||
|
slug_title_map = {
|
||||||
|
"default-provider-authorization-implicit-consent": "Redirecting to %(app)s",
|
||||||
|
"default-provider-authorization-explicit-consent": "Redirecting to %(app)s",
|
||||||
|
}
|
||||||
|
db_alias = schema_editor.connection.alias
|
||||||
|
Flow = apps.get_model("authentik_flows", "Flow")
|
||||||
|
for flow in Flow.objects.using(db_alias).all():
|
||||||
|
if flow.slug not in slug_title_map:
|
||||||
|
continue
|
||||||
|
flow.title = slug_title_map[flow.slug]
|
||||||
|
flow.save()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("authentik_flows", "0020_flowtoken"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [migrations.RunPython(update_title_for_defaults)]
|
@ -1,7 +1,7 @@
|
|||||||
"""Flow models"""
|
"""Flow models"""
|
||||||
from base64 import b64decode, b64encode
|
from base64 import b64decode, b64encode
|
||||||
from pickle import dumps, loads # nosec
|
from pickle import dumps, loads # nosec
|
||||||
from typing import TYPE_CHECKING, Optional, Type
|
from typing import TYPE_CHECKING, Optional
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
@ -63,7 +63,7 @@ class Stage(SerializerModel):
|
|||||||
objects = InheritanceManager()
|
objects = InheritanceManager()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def type(self) -> Type["StageView"]:
|
def type(self) -> type["StageView"]:
|
||||||
"""Return StageView class that implements logic for this stage"""
|
"""Return StageView class that implements logic for this stage"""
|
||||||
# This is a bit of a workaround, since we can't set class methods with setattr
|
# This is a bit of a workaround, since we can't set class methods with setattr
|
||||||
if hasattr(self, "__in_memory_type"):
|
if hasattr(self, "__in_memory_type"):
|
||||||
@ -86,7 +86,7 @@ class Stage(SerializerModel):
|
|||||||
return f"Stage {self.name}"
|
return f"Stage {self.name}"
|
||||||
|
|
||||||
|
|
||||||
def in_memory_stage(view: Type["StageView"]) -> Stage:
|
def in_memory_stage(view: type["StageView"]) -> Stage:
|
||||||
"""Creates an in-memory stage instance, based on a `view` as view."""
|
"""Creates an in-memory stage instance, based on a `view` as view."""
|
||||||
stage = Stage()
|
stage = Stage()
|
||||||
# Because we can't pickle a locally generated function,
|
# Because we can't pickle a locally generated function,
|
||||||
|
@ -4,7 +4,7 @@ from typing import Any, Optional
|
|||||||
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
from prometheus_client import Histogram
|
from prometheus_client import Gauge, Histogram
|
||||||
from sentry_sdk.hub import Hub
|
from sentry_sdk.hub import Hub
|
||||||
from sentry_sdk.tracing import Span
|
from sentry_sdk.tracing import Span
|
||||||
from structlog.stdlib import BoundLogger, get_logger
|
from structlog.stdlib import BoundLogger, get_logger
|
||||||
@ -13,10 +13,9 @@ from authentik.core.models import User
|
|||||||
from authentik.events.models import cleanse_dict
|
from authentik.events.models import cleanse_dict
|
||||||
from authentik.flows.exceptions import EmptyFlowException, FlowNonApplicableException
|
from authentik.flows.exceptions import EmptyFlowException, FlowNonApplicableException
|
||||||
from authentik.flows.markers import ReevaluateMarker, StageMarker
|
from authentik.flows.markers import ReevaluateMarker, StageMarker
|
||||||
from authentik.flows.models import Flow, FlowStageBinding, Stage
|
from authentik.flows.models import Flow, FlowDesignation, FlowStageBinding, Stage
|
||||||
from authentik.lib.config import CONFIG
|
from authentik.lib.config import CONFIG
|
||||||
from authentik.policies.engine import PolicyEngine
|
from authentik.policies.engine import PolicyEngine
|
||||||
from authentik.root.monitoring import UpdatingGauge
|
|
||||||
|
|
||||||
LOGGER = get_logger()
|
LOGGER = get_logger()
|
||||||
PLAN_CONTEXT_PENDING_USER = "pending_user"
|
PLAN_CONTEXT_PENDING_USER = "pending_user"
|
||||||
@ -27,10 +26,9 @@ PLAN_CONTEXT_SOURCE = "source"
|
|||||||
# Is set by the Flow Planner when a FlowToken was used, and the currently active flow plan
|
# Is set by the Flow Planner when a FlowToken was used, and the currently active flow plan
|
||||||
# was restored.
|
# was restored.
|
||||||
PLAN_CONTEXT_IS_RESTORED = "is_restored"
|
PLAN_CONTEXT_IS_RESTORED = "is_restored"
|
||||||
GAUGE_FLOWS_CACHED = UpdatingGauge(
|
GAUGE_FLOWS_CACHED = Gauge(
|
||||||
"authentik_flows_cached",
|
"authentik_flows_cached",
|
||||||
"Cached flows",
|
"Cached flows",
|
||||||
update_func=lambda: len(cache.keys("flow_*") or []),
|
|
||||||
)
|
)
|
||||||
HIST_FLOWS_PLAN_TIME = Histogram(
|
HIST_FLOWS_PLAN_TIME = Histogram(
|
||||||
"authentik_flows_plan_time",
|
"authentik_flows_plan_time",
|
||||||
@ -126,6 +124,8 @@ class FlowPlanner:
|
|||||||
) -> FlowPlan:
|
) -> FlowPlan:
|
||||||
"""Check each of the flows' policies, check policies for each stage with PolicyBinding
|
"""Check each of the flows' policies, check policies for each stage with PolicyBinding
|
||||||
and return ordered list"""
|
and return ordered list"""
|
||||||
|
if not default_context:
|
||||||
|
default_context = {}
|
||||||
with Hub.current.start_span(
|
with Hub.current.start_span(
|
||||||
op="authentik.flow.planner.plan", description=self.flow.slug
|
op="authentik.flow.planner.plan", description=self.flow.slug
|
||||||
) as span:
|
) as span:
|
||||||
@ -139,37 +139,37 @@ class FlowPlanner:
|
|||||||
# Bit of a workaround here, if there is a pending user set in the default context
|
# Bit of a workaround here, if there is a pending user set in the default context
|
||||||
# we use that user for our cache key
|
# we use that user for our cache key
|
||||||
# to make sure they don't get the generic response
|
# to make sure they don't get the generic response
|
||||||
if default_context and PLAN_CONTEXT_PENDING_USER in default_context:
|
if PLAN_CONTEXT_PENDING_USER not in default_context:
|
||||||
user = default_context[PLAN_CONTEXT_PENDING_USER]
|
default_context[PLAN_CONTEXT_PENDING_USER] = request.user
|
||||||
else:
|
user = default_context[PLAN_CONTEXT_PENDING_USER]
|
||||||
user = request.user
|
|
||||||
# First off, check the flow's direct policy bindings
|
# First off, check the flow's direct policy bindings
|
||||||
# to make sure the user even has access to the flow
|
# to make sure the user even has access to the flow
|
||||||
engine = PolicyEngine(self.flow, user, request)
|
engine = PolicyEngine(self.flow, user, request)
|
||||||
if default_context:
|
span.set_data("default_context", cleanse_dict(default_context))
|
||||||
span.set_data("default_context", cleanse_dict(default_context))
|
engine.request.context = default_context
|
||||||
engine.request.context = default_context
|
|
||||||
engine.build()
|
engine.build()
|
||||||
result = engine.result
|
result = engine.result
|
||||||
if not result.passing:
|
if not result.passing:
|
||||||
raise FlowNonApplicableException(",".join(result.messages))
|
exc = FlowNonApplicableException(",".join(result.messages))
|
||||||
|
exc.policy_result = result
|
||||||
|
raise exc
|
||||||
# User is passing so far, check if we have a cached plan
|
# User is passing so far, check if we have a cached plan
|
||||||
cached_plan_key = cache_key(self.flow, user)
|
cached_plan_key = cache_key(self.flow, user)
|
||||||
cached_plan = cache.get(cached_plan_key, None)
|
cached_plan = cache.get(cached_plan_key, None)
|
||||||
if cached_plan and self.use_cache:
|
if self.flow.designation not in [FlowDesignation.STAGE_CONFIGURATION]:
|
||||||
self._logger.debug(
|
if cached_plan and self.use_cache:
|
||||||
"f(plan): taking plan from cache",
|
self._logger.debug(
|
||||||
key=cached_plan_key,
|
"f(plan): taking plan from cache",
|
||||||
)
|
key=cached_plan_key,
|
||||||
# Reset the context as this isn't factored into caching
|
)
|
||||||
cached_plan.context = default_context or {}
|
# Reset the context as this isn't factored into caching
|
||||||
return cached_plan
|
cached_plan.context = default_context or {}
|
||||||
|
return cached_plan
|
||||||
self._logger.debug(
|
self._logger.debug(
|
||||||
"f(plan): building plan",
|
"f(plan): building plan",
|
||||||
)
|
)
|
||||||
plan = self._build_plan(user, request, default_context)
|
plan = self._build_plan(user, request, default_context)
|
||||||
cache.set(cache_key(self.flow, user), plan, CACHE_TIMEOUT)
|
cache.set(cache_key(self.flow, user), plan, CACHE_TIMEOUT)
|
||||||
GAUGE_FLOWS_CACHED.update()
|
|
||||||
if not plan.bindings and not self.allow_empty_flows:
|
if not plan.bindings and not self.allow_empty_flows:
|
||||||
raise EmptyFlowException()
|
raise EmptyFlowException()
|
||||||
return plan
|
return plan
|
||||||
|
@ -4,6 +4,9 @@ from django.db.models.signals import post_save, pre_delete
|
|||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from structlog.stdlib import get_logger
|
from structlog.stdlib import get_logger
|
||||||
|
|
||||||
|
from authentik.flows.planner import GAUGE_FLOWS_CACHED
|
||||||
|
from authentik.root.monitoring import monitoring_set
|
||||||
|
|
||||||
LOGGER = get_logger()
|
LOGGER = get_logger()
|
||||||
|
|
||||||
|
|
||||||
@ -14,6 +17,13 @@ def delete_cache_prefix(prefix: str) -> int:
|
|||||||
return len(keys)
|
return len(keys)
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(monitoring_set)
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def monitoring_set_flows(sender, **kwargs):
|
||||||
|
"""set flow gauges"""
|
||||||
|
GAUGE_FLOWS_CACHED.set(len(cache.keys("flow_*") or []))
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save)
|
@receiver(post_save)
|
||||||
@receiver(pre_delete)
|
@receiver(pre_delete)
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""authentik stage Base view"""
|
"""authentik stage Base view"""
|
||||||
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from django.contrib.auth.models import AnonymousUser
|
from django.contrib.auth.models import AnonymousUser
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
from django.http.request import QueryDict
|
from django.http.request import QueryDict
|
||||||
@ -11,15 +13,19 @@ from structlog.stdlib import get_logger
|
|||||||
|
|
||||||
from authentik.core.models import DEFAULT_AVATAR, User
|
from authentik.core.models import DEFAULT_AVATAR, User
|
||||||
from authentik.flows.challenge import (
|
from authentik.flows.challenge import (
|
||||||
|
AccessDeniedChallenge,
|
||||||
Challenge,
|
Challenge,
|
||||||
ChallengeResponse,
|
ChallengeResponse,
|
||||||
|
ChallengeTypes,
|
||||||
ContextualFlowInfo,
|
ContextualFlowInfo,
|
||||||
HttpChallengeResponse,
|
HttpChallengeResponse,
|
||||||
WithUserInfoChallenge,
|
WithUserInfoChallenge,
|
||||||
)
|
)
|
||||||
from authentik.flows.models import InvalidResponseAction
|
from authentik.flows.models import InvalidResponseAction
|
||||||
from authentik.flows.planner import PLAN_CONTEXT_APPLICATION, PLAN_CONTEXT_PENDING_USER
|
from authentik.flows.planner import PLAN_CONTEXT_APPLICATION, PLAN_CONTEXT_PENDING_USER
|
||||||
from authentik.flows.views.executor import FlowExecutorView
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from authentik.flows.views.executor import FlowExecutorView
|
||||||
|
|
||||||
PLAN_CONTEXT_PENDING_USER_IDENTIFIER = "pending_user_identifier"
|
PLAN_CONTEXT_PENDING_USER_IDENTIFIER = "pending_user_identifier"
|
||||||
LOGGER = get_logger()
|
LOGGER = get_logger()
|
||||||
@ -28,11 +34,11 @@ LOGGER = get_logger()
|
|||||||
class StageView(View):
|
class StageView(View):
|
||||||
"""Abstract Stage, inherits TemplateView but can be combined with FormView"""
|
"""Abstract Stage, inherits TemplateView but can be combined with FormView"""
|
||||||
|
|
||||||
executor: FlowExecutorView
|
executor: "FlowExecutorView"
|
||||||
|
|
||||||
request: HttpRequest = None
|
request: HttpRequest = None
|
||||||
|
|
||||||
def __init__(self, executor: FlowExecutorView, **kwargs):
|
def __init__(self, executor: "FlowExecutorView", **kwargs):
|
||||||
self.executor = executor
|
self.executor = executor
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
@ -43,6 +49,8 @@ class StageView(View):
|
|||||||
other things besides the form display.
|
other things besides the form display.
|
||||||
|
|
||||||
If no user is pending, returns request.user"""
|
If no user is pending, returns request.user"""
|
||||||
|
if not self.executor.plan:
|
||||||
|
return self.request.user
|
||||||
if PLAN_CONTEXT_PENDING_USER_IDENTIFIER in self.executor.plan.context and for_display:
|
if PLAN_CONTEXT_PENDING_USER_IDENTIFIER in self.executor.plan.context and for_display:
|
||||||
return User(
|
return User(
|
||||||
username=self.executor.plan.context.get(PLAN_CONTEXT_PENDING_USER_IDENTIFIER),
|
username=self.executor.plan.context.get(PLAN_CONTEXT_PENDING_USER_IDENTIFIER),
|
||||||
@ -108,9 +116,14 @@ class ChallengeStageView(StageView):
|
|||||||
|
|
||||||
def format_title(self) -> str:
|
def format_title(self) -> str:
|
||||||
"""Allow usage of placeholder in flow title."""
|
"""Allow usage of placeholder in flow title."""
|
||||||
return self.executor.flow.title % {
|
if not self.executor.plan:
|
||||||
"app": self.executor.plan.context.get(PLAN_CONTEXT_APPLICATION, "")
|
return self.executor.flow.title
|
||||||
}
|
try:
|
||||||
|
return self.executor.flow.title % {
|
||||||
|
"app": self.executor.plan.context.get(PLAN_CONTEXT_APPLICATION, "")
|
||||||
|
}
|
||||||
|
except ValueError:
|
||||||
|
return self.executor.flow.title
|
||||||
|
|
||||||
def _get_challenge(self, *args, **kwargs) -> Challenge:
|
def _get_challenge(self, *args, **kwargs) -> Challenge:
|
||||||
with Hub.current.start_span(
|
with Hub.current.start_span(
|
||||||
@ -169,3 +182,27 @@ class ChallengeStageView(StageView):
|
|||||||
stage_view=self,
|
stage_view=self,
|
||||||
)
|
)
|
||||||
return HttpChallengeResponse(challenge_response)
|
return HttpChallengeResponse(challenge_response)
|
||||||
|
|
||||||
|
|
||||||
|
class AccessDeniedChallengeView(ChallengeStageView):
|
||||||
|
"""Used internally by FlowExecutor's stage_invalid()"""
|
||||||
|
|
||||||
|
error_message: Optional[str]
|
||||||
|
|
||||||
|
def __init__(self, executor: "FlowExecutorView", error_message: Optional[str] = None, **kwargs):
|
||||||
|
super().__init__(executor, **kwargs)
|
||||||
|
self.error_message = error_message
|
||||||
|
|
||||||
|
def get_challenge(self, *args, **kwargs) -> Challenge:
|
||||||
|
return AccessDeniedChallenge(
|
||||||
|
data={
|
||||||
|
"error_message": self.error_message or "Unknown error",
|
||||||
|
"type": ChallengeTypes.NATIVE.value,
|
||||||
|
"component": "ak-stage-access-denied",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
# This can never be reached since this challenge is created on demand and only the
|
||||||
|
# .get() method is called
|
||||||
|
def challenge_valid(self, response: ChallengeResponse) -> HttpResponse: # pragma: no cover
|
||||||
|
return self.executor.cancel()
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
"""Test helpers"""
|
||||||
|
from json import loads
|
||||||
|
from typing import Any, Optional
|
||||||
|
|
||||||
|
from django.http.response import HttpResponse
|
||||||
|
from django.urls.base import reverse
|
||||||
|
from rest_framework.test import APITestCase
|
||||||
|
|
||||||
|
from authentik.core.models import User
|
||||||
|
from authentik.flows.challenge import ChallengeTypes
|
||||||
|
from authentik.flows.models import Flow
|
||||||
|
|
||||||
|
|
||||||
|
class FlowTestCase(APITestCase):
|
||||||
|
"""Helpers for testing flows and stages."""
|
||||||
|
|
||||||
|
# pylint: disable=invalid-name
|
||||||
|
def assertStageResponse(
|
||||||
|
self,
|
||||||
|
response: HttpResponse,
|
||||||
|
flow: Optional[Flow] = None,
|
||||||
|
user: Optional[User] = None,
|
||||||
|
**kwargs,
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Assert various attributes of a stage response"""
|
||||||
|
raw_response = loads(response.content.decode())
|
||||||
|
self.assertIsNotNone(raw_response["component"])
|
||||||
|
self.assertIsNotNone(raw_response["type"])
|
||||||
|
if flow:
|
||||||
|
self.assertIn("flow_info", raw_response)
|
||||||
|
self.assertEqual(raw_response["flow_info"]["background"], flow.background_url)
|
||||||
|
self.assertEqual(
|
||||||
|
raw_response["flow_info"]["cancel_url"], reverse("authentik_flows:cancel")
|
||||||
|
)
|
||||||
|
# We don't check the flow title since it will most likely go
|
||||||
|
# through ChallengeStageView.format_title() so might not match 1:1
|
||||||
|
# self.assertEqual(raw_response["flow_info"]["title"], flow.title)
|
||||||
|
self.assertIsNotNone(raw_response["flow_info"]["title"])
|
||||||
|
if user:
|
||||||
|
self.assertEqual(raw_response["pending_user"], user.username)
|
||||||
|
self.assertEqual(raw_response["pending_user_avatar"], user.avatar)
|
||||||
|
for key, expected in kwargs.items():
|
||||||
|
self.assertEqual(raw_response[key], expected)
|
||||||
|
return raw_response
|
||||||
|
|
||||||
|
# pylint: disable=invalid-name
|
||||||
|
def assertStageRedirects(self, response: HttpResponse, to: str) -> dict[str, Any]:
|
||||||
|
"""Wrapper around assertStageResponse that checks for a redirect"""
|
||||||
|
return self.assertStageResponse(
|
||||||
|
response, component="xak-flow-redirect", to=to, type=ChallengeTypes.REDIRECT.value
|
||||||
|
)
|
||||||
|
@ -4,16 +4,14 @@ from unittest.mock import MagicMock, PropertyMock, patch
|
|||||||
from django.http import HttpRequest, HttpResponse
|
from django.http import HttpRequest, HttpResponse
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.encoding import force_str
|
|
||||||
from rest_framework.test import APITestCase
|
|
||||||
|
|
||||||
from authentik.core.models import User
|
from authentik.core.models import User
|
||||||
from authentik.flows.challenge import ChallengeTypes
|
|
||||||
from authentik.flows.exceptions import FlowNonApplicableException
|
from authentik.flows.exceptions import FlowNonApplicableException
|
||||||
from authentik.flows.markers import ReevaluateMarker, StageMarker
|
from authentik.flows.markers import ReevaluateMarker, StageMarker
|
||||||
from authentik.flows.models import Flow, FlowDesignation, FlowStageBinding, InvalidResponseAction
|
from authentik.flows.models import Flow, FlowDesignation, FlowStageBinding, InvalidResponseAction
|
||||||
from authentik.flows.planner import FlowPlan, FlowPlanner
|
from authentik.flows.planner import FlowPlan, FlowPlanner
|
||||||
from authentik.flows.stage import PLAN_CONTEXT_PENDING_USER_IDENTIFIER, StageView
|
from authentik.flows.stage import PLAN_CONTEXT_PENDING_USER_IDENTIFIER, StageView
|
||||||
|
from authentik.flows.tests import FlowTestCase
|
||||||
from authentik.flows.views.executor import NEXT_ARG_NAME, SESSION_KEY_PLAN, FlowExecutorView
|
from authentik.flows.views.executor import NEXT_ARG_NAME, SESSION_KEY_PLAN, FlowExecutorView
|
||||||
from authentik.lib.config import CONFIG
|
from authentik.lib.config import CONFIG
|
||||||
from authentik.policies.dummy.models import DummyPolicy
|
from authentik.policies.dummy.models import DummyPolicy
|
||||||
@ -37,7 +35,7 @@ def to_stage_response(request: HttpRequest, source: HttpResponse):
|
|||||||
TO_STAGE_RESPONSE_MOCK = MagicMock(side_effect=to_stage_response)
|
TO_STAGE_RESPONSE_MOCK = MagicMock(side_effect=to_stage_response)
|
||||||
|
|
||||||
|
|
||||||
class TestFlowExecutor(APITestCase):
|
class TestFlowExecutor(FlowTestCase):
|
||||||
"""Test executor"""
|
"""Test executor"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -90,18 +88,11 @@ class TestFlowExecutor(APITestCase):
|
|||||||
reverse("authentik_api:flow-executor", kwargs={"flow_slug": flow.slug}),
|
reverse("authentik_api:flow-executor", kwargs={"flow_slug": flow.slug}),
|
||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertJSONEqual(
|
self.assertStageResponse(
|
||||||
force_str(response.content),
|
response,
|
||||||
{
|
flow=flow,
|
||||||
"component": "ak-stage-access-denied",
|
error_message=FlowNonApplicableException.__doc__,
|
||||||
"error_message": FlowNonApplicableException.__doc__,
|
component="ak-stage-access-denied",
|
||||||
"flow_info": {
|
|
||||||
"background": flow.background_url,
|
|
||||||
"cancel_url": reverse("authentik_flows:cancel"),
|
|
||||||
"title": "",
|
|
||||||
},
|
|
||||||
"type": ChallengeTypes.NATIVE.value,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@patch(
|
@patch(
|
||||||
@ -283,14 +274,7 @@ class TestFlowExecutor(APITestCase):
|
|||||||
# We do this request without the patch, so the policy results in false
|
# We do this request without the patch, so the policy results in false
|
||||||
response = self.client.post(exec_url)
|
response = self.client.post(exec_url)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertJSONEqual(
|
self.assertStageRedirects(response, reverse("authentik_core:root-redirect"))
|
||||||
force_str(response.content),
|
|
||||||
{
|
|
||||||
"component": "xak-flow-redirect",
|
|
||||||
"to": reverse("authentik_core:root-redirect"),
|
|
||||||
"type": ChallengeTypes.REDIRECT.value,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_reevaluate_keep(self):
|
def test_reevaluate_keep(self):
|
||||||
"""Test planner with re-evaluate (everything is kept)"""
|
"""Test planner with re-evaluate (everything is kept)"""
|
||||||
@ -360,14 +344,7 @@ class TestFlowExecutor(APITestCase):
|
|||||||
# We do this request without the patch, so the policy results in false
|
# We do this request without the patch, so the policy results in false
|
||||||
response = self.client.post(exec_url)
|
response = self.client.post(exec_url)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertJSONEqual(
|
self.assertStageRedirects(response, reverse("authentik_core:root-redirect"))
|
||||||
force_str(response.content),
|
|
||||||
{
|
|
||||||
"component": "xak-flow-redirect",
|
|
||||||
"to": reverse("authentik_core:root-redirect"),
|
|
||||||
"type": ChallengeTypes.REDIRECT.value,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_reevaluate_remove_consecutive(self):
|
def test_reevaluate_remove_consecutive(self):
|
||||||
"""Test planner with re-evaluate (consecutive stages are removed)"""
|
"""Test planner with re-evaluate (consecutive stages are removed)"""
|
||||||
@ -407,18 +384,7 @@ class TestFlowExecutor(APITestCase):
|
|||||||
# First request, run the planner
|
# First request, run the planner
|
||||||
response = self.client.get(exec_url)
|
response = self.client.get(exec_url)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertJSONEqual(
|
self.assertStageResponse(response, flow, component="ak-stage-dummy")
|
||||||
force_str(response.content),
|
|
||||||
{
|
|
||||||
"type": ChallengeTypes.NATIVE.value,
|
|
||||||
"component": "ak-stage-dummy",
|
|
||||||
"flow_info": {
|
|
||||||
"background": flow.background_url,
|
|
||||||
"cancel_url": reverse("authentik_flows:cancel"),
|
|
||||||
"title": "",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
plan: FlowPlan = self.client.session[SESSION_KEY_PLAN]
|
plan: FlowPlan = self.client.session[SESSION_KEY_PLAN]
|
||||||
|
|
||||||
@ -441,31 +407,13 @@ class TestFlowExecutor(APITestCase):
|
|||||||
# but it won't save it, hence we can't check the plan
|
# but it won't save it, hence we can't check the plan
|
||||||
response = self.client.get(exec_url)
|
response = self.client.get(exec_url)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertJSONEqual(
|
self.assertStageResponse(response, flow, component="ak-stage-dummy")
|
||||||
force_str(response.content),
|
|
||||||
{
|
|
||||||
"type": ChallengeTypes.NATIVE.value,
|
|
||||||
"component": "ak-stage-dummy",
|
|
||||||
"flow_info": {
|
|
||||||
"background": flow.background_url,
|
|
||||||
"cancel_url": reverse("authentik_flows:cancel"),
|
|
||||||
"title": "",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
# fourth request, this confirms the last stage (dummy4)
|
# fourth request, this confirms the last stage (dummy4)
|
||||||
# We do this request without the patch, so the policy results in false
|
# We do this request without the patch, so the policy results in false
|
||||||
response = self.client.post(exec_url)
|
response = self.client.post(exec_url)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertJSONEqual(
|
self.assertStageRedirects(response, reverse("authentik_core:root-redirect"))
|
||||||
force_str(response.content),
|
|
||||||
{
|
|
||||||
"component": "xak-flow-redirect",
|
|
||||||
"to": reverse("authentik_core:root-redirect"),
|
|
||||||
"type": ChallengeTypes.REDIRECT.value,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_stageview_user_identifier(self):
|
def test_stageview_user_identifier(self):
|
||||||
"""Test PLAN_CONTEXT_PENDING_USER_IDENTIFIER"""
|
"""Test PLAN_CONTEXT_PENDING_USER_IDENTIFIER"""
|
||||||
@ -532,35 +480,16 @@ class TestFlowExecutor(APITestCase):
|
|||||||
# First request, run the planner
|
# First request, run the planner
|
||||||
response = self.client.get(exec_url)
|
response = self.client.get(exec_url)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertJSONEqual(
|
self.assertStageResponse(
|
||||||
force_str(response.content),
|
response,
|
||||||
{
|
flow,
|
||||||
"type": ChallengeTypes.NATIVE.value,
|
component="ak-stage-identification",
|
||||||
"component": "ak-stage-identification",
|
password_fields=False,
|
||||||
"flow_info": {
|
primary_action="Log in",
|
||||||
"background": flow.background_url,
|
sources=[],
|
||||||
"cancel_url": reverse("authentik_flows:cancel"),
|
show_source_labels=False,
|
||||||
"title": "",
|
user_fields=[UserFields.E_MAIL],
|
||||||
},
|
|
||||||
"password_fields": False,
|
|
||||||
"primary_action": "Log in",
|
|
||||||
"sources": [],
|
|
||||||
"show_source_labels": False,
|
|
||||||
"user_fields": [UserFields.E_MAIL],
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
response = self.client.post(exec_url, {"uid_field": "invalid-string"}, follow=True)
|
response = self.client.post(exec_url, {"uid_field": "invalid-string"}, follow=True)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertJSONEqual(
|
self.assertStageResponse(response, flow, component="ak-stage-access-denied")
|
||||||
force_str(response.content),
|
|
||||||
{
|
|
||||||
"component": "ak-stage-access-denied",
|
|
||||||
"error_message": None,
|
|
||||||
"flow_info": {
|
|
||||||
"background": flow.background_url,
|
|
||||||
"cancel_url": reverse("authentik_flows:cancel"),
|
|
||||||
"title": "",
|
|
||||||
},
|
|
||||||
"type": ChallengeTypes.NATIVE.value,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
"""base model tests"""
|
"""base model tests"""
|
||||||
from typing import Callable, Type
|
from typing import Callable
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
@ -12,7 +12,7 @@ class TestModels(TestCase):
|
|||||||
"""Generic model properties tests"""
|
"""Generic model properties tests"""
|
||||||
|
|
||||||
|
|
||||||
def model_tester_factory(test_model: Type[Stage]) -> Callable:
|
def model_tester_factory(test_model: type[Stage]) -> Callable:
|
||||||
"""Test a form"""
|
"""Test a form"""
|
||||||
|
|
||||||
def tester(self: TestModels):
|
def tester(self: TestModels):
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
"""stage view tests"""
|
"""stage view tests"""
|
||||||
from typing import Callable, Type
|
from typing import Callable
|
||||||
|
|
||||||
from django.test import RequestFactory, TestCase
|
from django.test import RequestFactory, TestCase
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ class TestViews(TestCase):
|
|||||||
self.exec = FlowExecutorView(request=self.factory.get("/"))
|
self.exec = FlowExecutorView(request=self.factory.get("/"))
|
||||||
|
|
||||||
|
|
||||||
def view_tester_factory(view_class: Type[StageView]) -> Callable:
|
def view_tester_factory(view_class: type[StageView]) -> Callable:
|
||||||
"""Test a form"""
|
"""Test a form"""
|
||||||
|
|
||||||
def tester(self: TestViews):
|
def tester(self: TestViews):
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from json import loads
|
from json import loads
|
||||||
from typing import Any, Type
|
from typing import Any
|
||||||
|
|
||||||
from dacite import from_dict
|
from dacite import from_dict
|
||||||
from dacite.exceptions import DaciteError
|
from dacite.exceptions import DaciteError
|
||||||
@ -87,7 +87,7 @@ class FlowImporter:
|
|||||||
def _validate_single(self, entry: FlowBundleEntry) -> BaseSerializer:
|
def _validate_single(self, entry: FlowBundleEntry) -> BaseSerializer:
|
||||||
"""Validate a single entry"""
|
"""Validate a single entry"""
|
||||||
model_app_label, model_name = entry.model.split(".")
|
model_app_label, model_name = entry.model.split(".")
|
||||||
model: Type[SerializerModel] = apps.get_model(model_app_label, model_name)
|
model: type[SerializerModel] = apps.get_model(model_app_label, model_name)
|
||||||
if not isinstance(model(), ALLOWED_MODELS):
|
if not isinstance(model(), ALLOWED_MODELS):
|
||||||
raise EntryInvalidError(f"Model {model} not allowed")
|
raise EntryInvalidError(f"Model {model} not allowed")
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@ from django.http import Http404, HttpRequest, HttpResponse, HttpResponseRedirect
|
|||||||
from django.http.request import QueryDict
|
from django.http.request import QueryDict
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.urls.base import reverse
|
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views.decorators.clickjacking import xframe_options_sameorigin
|
from django.views.decorators.clickjacking import xframe_options_sameorigin
|
||||||
from django.views.generic import View
|
from django.views.generic import View
|
||||||
@ -26,7 +25,6 @@ from structlog.stdlib import BoundLogger, get_logger
|
|||||||
from authentik.core.models import USER_ATTRIBUTE_DEBUG
|
from authentik.core.models import USER_ATTRIBUTE_DEBUG
|
||||||
from authentik.events.models import Event, EventAction, cleanse_dict
|
from authentik.events.models import Event, EventAction, cleanse_dict
|
||||||
from authentik.flows.challenge import (
|
from authentik.flows.challenge import (
|
||||||
AccessDeniedChallenge,
|
|
||||||
Challenge,
|
Challenge,
|
||||||
ChallengeResponse,
|
ChallengeResponse,
|
||||||
ChallengeTypes,
|
ChallengeTypes,
|
||||||
@ -51,6 +49,7 @@ from authentik.flows.planner import (
|
|||||||
FlowPlan,
|
FlowPlan,
|
||||||
FlowPlanner,
|
FlowPlanner,
|
||||||
)
|
)
|
||||||
|
from authentik.flows.stage import AccessDeniedChallengeView
|
||||||
from authentik.lib.sentry import SentryIgnoredException
|
from authentik.lib.sentry import SentryIgnoredException
|
||||||
from authentik.lib.utils.errors import exception_to_string
|
from authentik.lib.utils.errors import exception_to_string
|
||||||
from authentik.lib.utils.reflection import all_subclasses, class_to_path
|
from authentik.lib.utils.reflection import all_subclasses, class_to_path
|
||||||
@ -371,12 +370,6 @@ class FlowExecutorView(APIView):
|
|||||||
NEXT_ARG_NAME, "authentik_core:root-redirect"
|
NEXT_ARG_NAME, "authentik_core:root-redirect"
|
||||||
)
|
)
|
||||||
self.cancel()
|
self.cancel()
|
||||||
Event.new(
|
|
||||||
action=EventAction.FLOW_EXECUTION,
|
|
||||||
flow=self.flow,
|
|
||||||
designation=self.flow.designation,
|
|
||||||
successful=True,
|
|
||||||
).from_http(self.request)
|
|
||||||
return to_stage_response(self.request, redirect_with_qs(next_param))
|
return to_stage_response(self.request, redirect_with_qs(next_param))
|
||||||
|
|
||||||
def stage_ok(self) -> HttpResponse:
|
def stage_ok(self) -> HttpResponse:
|
||||||
@ -412,21 +405,9 @@ class FlowExecutorView(APIView):
|
|||||||
is a superuser."""
|
is a superuser."""
|
||||||
self._logger.debug("f(exec): Stage invalid")
|
self._logger.debug("f(exec): Stage invalid")
|
||||||
self.cancel()
|
self.cancel()
|
||||||
response = HttpChallengeResponse(
|
challenge_view = AccessDeniedChallengeView(self, error_message)
|
||||||
AccessDeniedChallenge(
|
challenge_view.request = self.request
|
||||||
{
|
return to_stage_response(self.request, challenge_view.get(self.request))
|
||||||
"error_message": error_message,
|
|
||||||
"type": ChallengeTypes.NATIVE.value,
|
|
||||||
"component": "ak-stage-access-denied",
|
|
||||||
"flow_info": {
|
|
||||||
"title": self.flow.title,
|
|
||||||
"background": self.flow.background_url,
|
|
||||||
"cancel_url": reverse("authentik_flows:cancel"),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return to_stage_response(self.request, response)
|
|
||||||
|
|
||||||
def cancel(self):
|
def cancel(self):
|
||||||
"""Cancel current execution and return a redirect"""
|
"""Cancel current execution and return a redirect"""
|
||||||
|
@ -5,16 +5,6 @@ postgresql:
|
|||||||
user: authentik
|
user: authentik
|
||||||
port: 5432
|
port: 5432
|
||||||
password: 'env://POSTGRES_PASSWORD'
|
password: 'env://POSTGRES_PASSWORD'
|
||||||
backup:
|
|
||||||
enabled: true
|
|
||||||
s3_backup:
|
|
||||||
access_key: ""
|
|
||||||
secret_key: ""
|
|
||||||
bucket: ""
|
|
||||||
region: eu-central-1
|
|
||||||
host: ""
|
|
||||||
location: ""
|
|
||||||
insecure_skip_verify: false
|
|
||||||
|
|
||||||
web:
|
web:
|
||||||
listen: 0.0.0.0:9000
|
listen: 0.0.0.0:9000
|
||||||
@ -65,19 +55,17 @@ outposts:
|
|||||||
# %(version)s: Current version; 2021.4.1
|
# %(version)s: Current version; 2021.4.1
|
||||||
# %(build_hash)s: Build hash if you're running a beta version
|
# %(build_hash)s: Build hash if you're running a beta version
|
||||||
container_image_base: ghcr.io/goauthentik/%(type)s:%(version)s
|
container_image_base: ghcr.io/goauthentik/%(type)s:%(version)s
|
||||||
|
discover: true
|
||||||
|
|
||||||
cookie_domain: null
|
cookie_domain: null
|
||||||
disable_update_check: false
|
disable_update_check: false
|
||||||
disable_startup_analytics: false
|
disable_startup_analytics: false
|
||||||
avatars: env://AUTHENTIK_AUTHENTIK__AVATARS?gravatar
|
avatars: env://AUTHENTIK_AUTHENTIK__AVATARS?gravatar
|
||||||
geoip: "./GeoLite2-City.mmdb"
|
geoip: "/geoip/GeoLite2-City.mmdb"
|
||||||
|
|
||||||
footer_links:
|
footer_links: []
|
||||||
- name: Documentation
|
|
||||||
href: https://goauthentik.io/docs/?utm_source=authentik
|
|
||||||
- name: authentik Website
|
|
||||||
href: https://goauthentik.io/?utm_source=authentik
|
|
||||||
|
|
||||||
|
default_user_change_name: true
|
||||||
default_user_change_email: true
|
default_user_change_email: true
|
||||||
default_user_change_username: true
|
default_user_change_username: true
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ class BaseEvaluator:
|
|||||||
self._globals = {
|
self._globals = {
|
||||||
"regex_match": BaseEvaluator.expr_regex_match,
|
"regex_match": BaseEvaluator.expr_regex_match,
|
||||||
"regex_replace": BaseEvaluator.expr_regex_replace,
|
"regex_replace": BaseEvaluator.expr_regex_replace,
|
||||||
|
"list_flatten": BaseEvaluator.expr_flatten,
|
||||||
"ak_is_group_member": BaseEvaluator.expr_is_group_member,
|
"ak_is_group_member": BaseEvaluator.expr_is_group_member,
|
||||||
"ak_user_by": BaseEvaluator.expr_user_by,
|
"ak_user_by": BaseEvaluator.expr_user_by,
|
||||||
"ak_logger": get_logger(),
|
"ak_logger": get_logger(),
|
||||||
@ -40,6 +41,15 @@ class BaseEvaluator:
|
|||||||
self._context = {}
|
self._context = {}
|
||||||
self._filename = "BaseEvalautor"
|
self._filename = "BaseEvalautor"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def expr_flatten(value: list[Any] | Any) -> Optional[Any]:
|
||||||
|
"""Flatten `value` if its a list"""
|
||||||
|
if isinstance(value, list):
|
||||||
|
if len(value) < 1:
|
||||||
|
return None
|
||||||
|
return value[0]
|
||||||
|
return value
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def expr_regex_match(value: Any, regex: str) -> bool:
|
def expr_regex_match(value: Any, regex: str) -> bool:
|
||||||
"""Expression Filter to run re.search"""
|
"""Expression Filter to run re.search"""
|
||||||
|
6
authentik/lib/merge.py
Normal file
6
authentik/lib/merge.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
"""merge utils"""
|
||||||
|
from deepmerge import Merger
|
||||||
|
|
||||||
|
MERGE_LIST_UNIQUE = Merger(
|
||||||
|
[(list, ["append_unique"]), (dict, ["merge"]), (set, ["union"])], ["override"], ["override"]
|
||||||
|
)
|
@ -3,8 +3,6 @@ from typing import Optional
|
|||||||
|
|
||||||
from aioredis.errors import ConnectionClosedError, ReplyError
|
from aioredis.errors import ConnectionClosedError, ReplyError
|
||||||
from billiard.exceptions import SoftTimeLimitExceeded, WorkerLostError
|
from billiard.exceptions import SoftTimeLimitExceeded, WorkerLostError
|
||||||
from botocore.client import ClientError
|
|
||||||
from botocore.exceptions import BotoCoreError
|
|
||||||
from celery.exceptions import CeleryError
|
from celery.exceptions import CeleryError
|
||||||
from channels.middleware import BaseMiddleware
|
from channels.middleware import BaseMiddleware
|
||||||
from channels_redis.core import ChannelFull
|
from channels_redis.core import ChannelFull
|
||||||
@ -81,9 +79,6 @@ def before_send(event: dict, hint: dict) -> Optional[dict]:
|
|||||||
WorkerLostError,
|
WorkerLostError,
|
||||||
CeleryError,
|
CeleryError,
|
||||||
SoftTimeLimitExceeded,
|
SoftTimeLimitExceeded,
|
||||||
# S3 errors
|
|
||||||
BotoCoreError,
|
|
||||||
ClientError,
|
|
||||||
# custom baseclass
|
# custom baseclass
|
||||||
SentryIgnoredException,
|
SentryIgnoredException,
|
||||||
# ldap errors
|
# ldap errors
|
||||||
@ -97,12 +92,10 @@ def before_send(event: dict, hint: dict) -> Optional[dict]:
|
|||||||
if "exc_info" in hint:
|
if "exc_info" in hint:
|
||||||
_, exc_value, _ = hint["exc_info"]
|
_, exc_value, _ = hint["exc_info"]
|
||||||
if isinstance(exc_value, ignored_classes):
|
if isinstance(exc_value, ignored_classes):
|
||||||
LOGGER.debug("dropping exception", exception=exc_value)
|
LOGGER.debug("dropping exception", exc=exc_value)
|
||||||
return None
|
return None
|
||||||
if "logger" in event:
|
if "logger" in event:
|
||||||
if event["logger"] in [
|
if event["logger"] in [
|
||||||
"dbbackup",
|
|
||||||
"botocore",
|
|
||||||
"kombu",
|
"kombu",
|
||||||
"asyncio",
|
"asyncio",
|
||||||
"multiprocessing",
|
"multiprocessing",
|
||||||
@ -111,9 +104,10 @@ def before_send(event: dict, hint: dict) -> Optional[dict]:
|
|||||||
"django_redis.cache",
|
"django_redis.cache",
|
||||||
"celery.backends.redis",
|
"celery.backends.redis",
|
||||||
"celery.worker",
|
"celery.worker",
|
||||||
|
"paramiko.transport",
|
||||||
]:
|
]:
|
||||||
return None
|
return None
|
||||||
LOGGER.debug("sending event to sentry", exc=exc_value, source_logger=event.get("logger", None))
|
LOGGER.debug("sending event to sentry", exc=exc_value, source_logger=event.get("logger", None))
|
||||||
if settings.DEBUG:
|
if settings.DEBUG or settings.TEST:
|
||||||
return None
|
return None
|
||||||
return event
|
return event
|
||||||
|
@ -13,4 +13,4 @@ class TestSentry(TestCase):
|
|||||||
|
|
||||||
def test_error_sent(self):
|
def test_error_sent(self):
|
||||||
"""Test error sent"""
|
"""Test error sent"""
|
||||||
self.assertEqual({}, before_send({}, {"exc_info": (0, ValueError(), 0)}))
|
self.assertEqual(None, before_send({}, {"exc_info": (0, ValueError(), 0)}))
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
"""base model tests"""
|
"""base model tests"""
|
||||||
from typing import Callable, Type
|
from typing import Callable
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from rest_framework.serializers import BaseSerializer
|
from rest_framework.serializers import BaseSerializer
|
||||||
@ -13,7 +13,7 @@ class TestModels(TestCase):
|
|||||||
"""Generic model properties tests"""
|
"""Generic model properties tests"""
|
||||||
|
|
||||||
|
|
||||||
def model_tester_factory(test_model: Type[Stage]) -> Callable:
|
def model_tester_factory(test_model: type[Stage]) -> Callable:
|
||||||
"""Test a form"""
|
"""Test a form"""
|
||||||
|
|
||||||
def tester(self: TestModels):
|
def tester(self: TestModels):
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""http helpers"""
|
"""http helpers"""
|
||||||
from os import environ
|
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
@ -7,7 +6,7 @@ from requests.sessions import Session
|
|||||||
from sentry_sdk.hub import Hub
|
from sentry_sdk.hub import Hub
|
||||||
from structlog.stdlib import get_logger
|
from structlog.stdlib import get_logger
|
||||||
|
|
||||||
from authentik import ENV_GIT_HASH_KEY, __version__
|
from authentik import get_full_version
|
||||||
|
|
||||||
OUTPOST_REMOTE_IP_HEADER = "HTTP_X_AUTHENTIK_REMOTE_IP"
|
OUTPOST_REMOTE_IP_HEADER = "HTTP_X_AUTHENTIK_REMOTE_IP"
|
||||||
OUTPOST_TOKEN_HEADER = "HTTP_X_AUTHENTIK_OUTPOST_TOKEN" # nosec
|
OUTPOST_TOKEN_HEADER = "HTTP_X_AUTHENTIK_OUTPOST_TOKEN" # nosec
|
||||||
@ -75,8 +74,7 @@ def get_client_ip(request: Optional[HttpRequest]) -> str:
|
|||||||
|
|
||||||
def authentik_user_agent() -> str:
|
def authentik_user_agent() -> str:
|
||||||
"""Get a common user agent"""
|
"""Get a common user agent"""
|
||||||
build = environ.get(ENV_GIT_HASH_KEY, "tagged")
|
return f"authentik@{get_full_version()}"
|
||||||
return f"authentik@{__version__} (build={build})"
|
|
||||||
|
|
||||||
|
|
||||||
def get_http_session() -> Session:
|
def get_http_session() -> Session:
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
import os
|
import os
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from kubernetes.config.incluster_config import SERVICE_HOST_ENV_NAME
|
from kubernetes.config.incluster_config import SERVICE_HOST_ENV_NAME
|
||||||
@ -30,7 +29,7 @@ def class_to_path(cls: type) -> str:
|
|||||||
return f"{cls.__module__}.{cls.__name__}"
|
return f"{cls.__module__}.{cls.__name__}"
|
||||||
|
|
||||||
|
|
||||||
def path_to_class(path: Union[str, None]) -> Union[type, None]:
|
def path_to_class(path: str | None) -> type | None:
|
||||||
"""Import module and return class"""
|
"""Import module and return class"""
|
||||||
if not path:
|
if not path:
|
||||||
return None
|
return None
|
||||||
@ -59,4 +58,6 @@ def get_env() -> str:
|
|||||||
return "compose"
|
return "compose"
|
||||||
if CONFIG.y_bool("debug"):
|
if CONFIG.y_bool("debug"):
|
||||||
return "dev"
|
return "dev"
|
||||||
|
if "AK_APPLIANCE" in os.environ:
|
||||||
|
return os.environ["AK_APPLIANCE"]
|
||||||
return "custom"
|
return "custom"
|
||||||
|
@ -34,7 +34,7 @@ def timedelta_from_string(expr: str) -> datetime.timedelta:
|
|||||||
key, value = duration_pair.split("=")
|
key, value = duration_pair.split("=")
|
||||||
if key.lower() not in ALLOWED_KEYS:
|
if key.lower() not in ALLOWED_KEYS:
|
||||||
continue
|
continue
|
||||||
kwargs[key.lower()] = float(value)
|
kwargs[key.lower()] = float(value.strip())
|
||||||
if len(kwargs) < 1:
|
if len(kwargs) < 1:
|
||||||
raise ValueError("No valid keys to pass to timedelta")
|
raise ValueError("No valid keys to pass to timedelta")
|
||||||
return datetime.timedelta(**kwargs)
|
return datetime.timedelta(**kwargs)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
"""Managed objects manager"""
|
"""Managed objects manager"""
|
||||||
from typing import Callable, Optional, Type
|
from typing import Callable, Optional
|
||||||
|
|
||||||
from structlog.stdlib import get_logger
|
from structlog.stdlib import get_logger
|
||||||
|
|
||||||
@ -11,11 +11,11 @@ LOGGER = get_logger()
|
|||||||
class EnsureOp:
|
class EnsureOp:
|
||||||
"""Ensure operation, executed as part of an ObjectManager run"""
|
"""Ensure operation, executed as part of an ObjectManager run"""
|
||||||
|
|
||||||
_obj: Type[ManagedModel]
|
_obj: type[ManagedModel]
|
||||||
_managed_uid: str
|
_managed_uid: str
|
||||||
_kwargs: dict
|
_kwargs: dict
|
||||||
|
|
||||||
def __init__(self, obj: Type[ManagedModel], managed_uid: str, **kwargs) -> None:
|
def __init__(self, obj: type[ManagedModel], managed_uid: str, **kwargs) -> None:
|
||||||
self._obj = obj
|
self._obj = obj
|
||||||
self._managed_uid = managed_uid
|
self._managed_uid = managed_uid
|
||||||
self._kwargs = kwargs
|
self._kwargs = kwargs
|
||||||
@ -32,7 +32,7 @@ class EnsureExists(EnsureOp):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
obj: Type[ManagedModel],
|
obj: type[ManagedModel],
|
||||||
managed_uid: str,
|
managed_uid: str,
|
||||||
created_callback: Optional[Callable] = None,
|
created_callback: Optional[Callable] = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
|
@ -12,6 +12,7 @@ from rest_framework.response import Response
|
|||||||
from rest_framework.serializers import JSONField, ModelSerializer, ValidationError
|
from rest_framework.serializers import JSONField, ModelSerializer, ValidationError
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
|
from authentik import get_build_hash
|
||||||
from authentik.core.api.providers import ProviderSerializer
|
from authentik.core.api.providers import ProviderSerializer
|
||||||
from authentik.core.api.used_by import UsedByMixin
|
from authentik.core.api.used_by import UsedByMixin
|
||||||
from authentik.core.api.utils import PassiveSerializer, is_dict
|
from authentik.core.api.utils import PassiveSerializer, is_dict
|
||||||
@ -98,8 +99,12 @@ class OutpostHealthSerializer(PassiveSerializer):
|
|||||||
last_seen = DateTimeField(read_only=True)
|
last_seen = DateTimeField(read_only=True)
|
||||||
version = CharField(read_only=True)
|
version = CharField(read_only=True)
|
||||||
version_should = CharField(read_only=True)
|
version_should = CharField(read_only=True)
|
||||||
|
|
||||||
version_outdated = BooleanField(read_only=True)
|
version_outdated = BooleanField(read_only=True)
|
||||||
|
|
||||||
|
build_hash = CharField(read_only=True, required=False)
|
||||||
|
build_hash_should = CharField(read_only=True, required=False)
|
||||||
|
|
||||||
|
|
||||||
class OutpostFilter(FilterSet):
|
class OutpostFilter(FilterSet):
|
||||||
"""Filter for Outposts"""
|
"""Filter for Outposts"""
|
||||||
@ -146,6 +151,8 @@ class OutpostViewSet(UsedByMixin, ModelViewSet):
|
|||||||
"version": state.version,
|
"version": state.version,
|
||||||
"version_should": state.version_should,
|
"version_should": state.version_should,
|
||||||
"version_outdated": state.version_outdated,
|
"version_outdated": state.version_outdated,
|
||||||
|
"build_hash": state.build_hash,
|
||||||
|
"build_hash_should": get_build_hash(),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return Response(OutpostHealthSerializer(states, many=True).data)
|
return Response(OutpostHealthSerializer(states, many=True).data)
|
||||||
|
@ -55,6 +55,10 @@ class OutpostConsumer(AuthJsonConsumer):
|
|||||||
|
|
||||||
first_msg = False
|
first_msg = False
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.logger = get_logger()
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
super().connect()
|
super().connect()
|
||||||
uuid = self.scope["url_route"]["kwargs"]["pk"]
|
uuid = self.scope["url_route"]["kwargs"]["pk"]
|
||||||
@ -65,7 +69,7 @@ class OutpostConsumer(AuthJsonConsumer):
|
|||||||
)
|
)
|
||||||
if not outpost:
|
if not outpost:
|
||||||
raise DenyConnection()
|
raise DenyConnection()
|
||||||
self.logger = get_logger().bind(outpost=outpost)
|
self.logger = self.logger.bind(outpost=outpost)
|
||||||
try:
|
try:
|
||||||
self.accept()
|
self.accept()
|
||||||
except RuntimeError as exc:
|
except RuntimeError as exc:
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
"""Base Controller"""
|
"""Base Controller"""
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from os import environ
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from structlog.stdlib import get_logger
|
from structlog.stdlib import get_logger
|
||||||
from structlog.testing import capture_logs
|
from structlog.testing import capture_logs
|
||||||
|
|
||||||
from authentik import ENV_GIT_HASH_KEY, __version__
|
from authentik import __version__, get_build_hash
|
||||||
from authentik.lib.config import CONFIG
|
from authentik.lib.config import CONFIG
|
||||||
from authentik.lib.sentry import SentryIgnoredException
|
from authentik.lib.sentry import SentryIgnoredException
|
||||||
from authentik.outposts.models import Outpost, OutpostServiceConnection
|
from authentik.outposts.models import (
|
||||||
|
Outpost,
|
||||||
|
OutpostServiceConnection,
|
||||||
|
OutpostServiceConnectionState,
|
||||||
|
)
|
||||||
|
|
||||||
FIELD_MANAGER = "goauthentik.io"
|
FIELD_MANAGER = "goauthentik.io"
|
||||||
|
|
||||||
@ -28,11 +31,25 @@ class DeploymentPort:
|
|||||||
inner_port: Optional[int] = None
|
inner_port: Optional[int] = None
|
||||||
|
|
||||||
|
|
||||||
|
class BaseClient:
|
||||||
|
"""Base class for custom clients"""
|
||||||
|
|
||||||
|
def fetch_state(self) -> OutpostServiceConnectionState:
|
||||||
|
"""Get state, version info"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
|
"""Cleanup after usage"""
|
||||||
|
|
||||||
|
|
||||||
class BaseController:
|
class BaseController:
|
||||||
"""Base Outpost deployment controller"""
|
"""Base Outpost deployment controller"""
|
||||||
|
|
||||||
deployment_ports: list[DeploymentPort]
|
deployment_ports: list[DeploymentPort]
|
||||||
|
client: BaseClient
|
||||||
outpost: Outpost
|
outpost: Outpost
|
||||||
connection: OutpostServiceConnection
|
connection: OutpostServiceConnection
|
||||||
|
|
||||||
@ -63,6 +80,14 @@ class BaseController:
|
|||||||
self.down()
|
self.down()
|
||||||
return [x["event"] for x in logs]
|
return [x["event"] for x in logs]
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
|
"""Cleanup after usage"""
|
||||||
|
if hasattr(self, "client"):
|
||||||
|
self.client.__exit__(exc_type, exc_value, traceback)
|
||||||
|
|
||||||
def get_static_deployment(self) -> str:
|
def get_static_deployment(self) -> str:
|
||||||
"""Return a static deployment configuration"""
|
"""Return a static deployment configuration"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
@ -76,5 +101,5 @@ class BaseController:
|
|||||||
return image_name_template % {
|
return image_name_template % {
|
||||||
"type": self.outpost.type,
|
"type": self.outpost.type,
|
||||||
"version": __version__,
|
"version": __version__,
|
||||||
"build_hash": environ.get(ENV_GIT_HASH_KEY, ""),
|
"build_hash": get_build_hash(),
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,79 @@
|
|||||||
"""Docker controller"""
|
"""Docker controller"""
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
from typing import Optional
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.text import slugify
|
from django.utils.text import slugify
|
||||||
from docker import DockerClient
|
from docker import DockerClient as UpstreamDockerClient
|
||||||
from docker.errors import DockerException, NotFound
|
from docker.errors import DockerException, NotFound
|
||||||
from docker.models.containers import Container
|
from docker.models.containers import Container
|
||||||
|
from docker.utils.utils import kwargs_from_env
|
||||||
|
from paramiko.ssh_exception import SSHException
|
||||||
|
from structlog.stdlib import get_logger
|
||||||
from yaml import safe_dump
|
from yaml import safe_dump
|
||||||
|
|
||||||
from authentik import __version__
|
from authentik import __version__
|
||||||
from authentik.outposts.controllers.base import BaseController, ControllerException
|
from authentik.outposts.controllers.base import BaseClient, BaseController, ControllerException
|
||||||
|
from authentik.outposts.docker_ssh import DockerInlineSSH
|
||||||
|
from authentik.outposts.docker_tls import DockerInlineTLS
|
||||||
from authentik.outposts.managed import MANAGED_OUTPOST
|
from authentik.outposts.managed import MANAGED_OUTPOST
|
||||||
from authentik.outposts.models import DockerServiceConnection, Outpost, ServiceConnectionInvalid
|
from authentik.outposts.models import (
|
||||||
|
DockerServiceConnection,
|
||||||
|
Outpost,
|
||||||
|
OutpostServiceConnectionState,
|
||||||
|
ServiceConnectionInvalid,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class DockerClient(UpstreamDockerClient, BaseClient):
|
||||||
|
"""Custom docker client, which can handle TLS and SSH from a database."""
|
||||||
|
|
||||||
|
tls: Optional[DockerInlineTLS]
|
||||||
|
ssh: Optional[DockerInlineSSH]
|
||||||
|
|
||||||
|
def __init__(self, connection: DockerServiceConnection):
|
||||||
|
self.tls = None
|
||||||
|
self.ssh = None
|
||||||
|
if connection.local:
|
||||||
|
# Same result as DockerClient.from_env
|
||||||
|
super().__init__(**kwargs_from_env())
|
||||||
|
else:
|
||||||
|
parsed_url = urlparse(connection.url)
|
||||||
|
tls_config = False
|
||||||
|
if parsed_url.scheme == "ssh":
|
||||||
|
self.ssh = DockerInlineSSH(parsed_url.hostname, connection.tls_authentication)
|
||||||
|
self.ssh.write()
|
||||||
|
else:
|
||||||
|
self.tls = DockerInlineTLS(
|
||||||
|
verification_kp=connection.tls_verification,
|
||||||
|
authentication_kp=connection.tls_authentication,
|
||||||
|
)
|
||||||
|
tls_config = self.tls.write()
|
||||||
|
try:
|
||||||
|
super().__init__(
|
||||||
|
base_url=connection.url,
|
||||||
|
tls=tls_config,
|
||||||
|
)
|
||||||
|
except SSHException as exc:
|
||||||
|
raise ServiceConnectionInvalid from exc
|
||||||
|
self.logger = get_logger()
|
||||||
|
# Ensure the client actually works
|
||||||
|
self.containers.list()
|
||||||
|
|
||||||
|
def fetch_state(self) -> OutpostServiceConnectionState:
|
||||||
|
try:
|
||||||
|
return OutpostServiceConnectionState(version=self.info()["ServerVersion"], healthy=True)
|
||||||
|
except (ServiceConnectionInvalid, DockerException):
|
||||||
|
return OutpostServiceConnectionState(version="", healthy=False)
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
|
if self.tls:
|
||||||
|
self.logger.debug("Cleaning up TLS")
|
||||||
|
self.tls.cleanup()
|
||||||
|
if self.ssh:
|
||||||
|
self.logger.debug("Cleaning up SSH")
|
||||||
|
self.ssh.cleanup()
|
||||||
|
|
||||||
|
|
||||||
class DockerController(BaseController):
|
class DockerController(BaseController):
|
||||||
@ -27,8 +89,9 @@ class DockerController(BaseController):
|
|||||||
if outpost.managed == MANAGED_OUTPOST:
|
if outpost.managed == MANAGED_OUTPOST:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
self.client = connection.client()
|
self.client = DockerClient(connection)
|
||||||
except ServiceConnectionInvalid as exc:
|
except DockerException as exc:
|
||||||
|
self.logger.warning(exc)
|
||||||
raise ControllerException from exc
|
raise ControllerException from exc
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -43,9 +106,12 @@ class DockerController(BaseController):
|
|||||||
).lower()
|
).lower()
|
||||||
|
|
||||||
def _get_labels(self) -> dict[str, str]:
|
def _get_labels(self) -> dict[str, str]:
|
||||||
return {
|
labels = {
|
||||||
"io.goauthentik.outpost-uuid": self.outpost.pk.hex,
|
"io.goauthentik.outpost-uuid": self.outpost.pk.hex,
|
||||||
}
|
}
|
||||||
|
if self.outpost.config.docker_labels:
|
||||||
|
labels.update(self.outpost.config.docker_labels)
|
||||||
|
return labels
|
||||||
|
|
||||||
def _get_env(self) -> dict[str, str]:
|
def _get_env(self) -> dict[str, str]:
|
||||||
return {
|
return {
|
||||||
|
@ -18,6 +18,7 @@ from kubernetes.client import (
|
|||||||
V1SecretKeySelector,
|
V1SecretKeySelector,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from authentik import __version__, get_full_version
|
||||||
from authentik.outposts.controllers.base import FIELD_MANAGER
|
from authentik.outposts.controllers.base import FIELD_MANAGER
|
||||||
from authentik.outposts.controllers.k8s.base import KubernetesObjectReconciler
|
from authentik.outposts.controllers.k8s.base import KubernetesObjectReconciler
|
||||||
from authentik.outposts.controllers.k8s.triggers import NeedsUpdate
|
from authentik.outposts.controllers.k8s.triggers import NeedsUpdate
|
||||||
@ -52,15 +53,18 @@ class DeploymentReconciler(KubernetesObjectReconciler[V1Deployment]):
|
|||||||
raise NeedsUpdate()
|
raise NeedsUpdate()
|
||||||
super().reconcile(current, reference)
|
super().reconcile(current, reference)
|
||||||
|
|
||||||
def get_pod_meta(self) -> dict[str, str]:
|
def get_pod_meta(self, **kwargs) -> dict[str, str]:
|
||||||
"""Get common object metadata"""
|
"""Get common object metadata"""
|
||||||
return {
|
kwargs.update(
|
||||||
"app.kubernetes.io/name": "authentik-outpost",
|
{
|
||||||
"app.kubernetes.io/managed-by": "goauthentik.io",
|
"app.kubernetes.io/name": f"authentik-outpost-{self.outpost.type}",
|
||||||
"goauthentik.io/outpost-uuid": self.controller.outpost.uuid.hex,
|
"app.kubernetes.io/managed-by": "goauthentik.io",
|
||||||
"goauthentik.io/outpost-name": slugify(self.controller.outpost.name),
|
"goauthentik.io/outpost-uuid": self.controller.outpost.uuid.hex,
|
||||||
"goauthentik.io/outpost-type": str(self.controller.outpost.type),
|
"goauthentik.io/outpost-name": slugify(self.controller.outpost.name),
|
||||||
}
|
"goauthentik.io/outpost-type": str(self.controller.outpost.type),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return kwargs
|
||||||
|
|
||||||
def get_reference_object(self) -> V1Deployment:
|
def get_reference_object(self) -> V1Deployment:
|
||||||
"""Get deployment object for outpost"""
|
"""Get deployment object for outpost"""
|
||||||
@ -77,13 +81,24 @@ class DeploymentReconciler(KubernetesObjectReconciler[V1Deployment]):
|
|||||||
meta = self.get_object_meta(name=self.name)
|
meta = self.get_object_meta(name=self.name)
|
||||||
image_name = self.controller.get_container_image()
|
image_name = self.controller.get_container_image()
|
||||||
image_pull_secrets = self.outpost.config.kubernetes_image_pull_secrets
|
image_pull_secrets = self.outpost.config.kubernetes_image_pull_secrets
|
||||||
|
version = get_full_version()
|
||||||
return V1Deployment(
|
return V1Deployment(
|
||||||
metadata=meta,
|
metadata=meta,
|
||||||
spec=V1DeploymentSpec(
|
spec=V1DeploymentSpec(
|
||||||
replicas=self.outpost.config.kubernetes_replicas,
|
replicas=self.outpost.config.kubernetes_replicas,
|
||||||
selector=V1LabelSelector(match_labels=self.get_pod_meta()),
|
selector=V1LabelSelector(match_labels=self.get_pod_meta()),
|
||||||
template=V1PodTemplateSpec(
|
template=V1PodTemplateSpec(
|
||||||
metadata=V1ObjectMeta(labels=self.get_pod_meta()),
|
metadata=V1ObjectMeta(
|
||||||
|
labels=self.get_pod_meta(
|
||||||
|
**{
|
||||||
|
# Support istio-specific labels, but also use the standard k8s
|
||||||
|
# recommendations
|
||||||
|
"app.kubernetes.io/version": version,
|
||||||
|
"app": "authentik-outpost",
|
||||||
|
"version": version,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
),
|
||||||
spec=V1PodSpec(
|
spec=V1PodSpec(
|
||||||
image_pull_secrets=[
|
image_pull_secrets=[
|
||||||
V1ObjectReference(name=secret) for secret in image_pull_secrets
|
V1ObjectReference(name=secret) for secret in image_pull_secrets
|
||||||
|
@ -6,6 +6,7 @@ from kubernetes.client import CoreV1Api, V1Service, V1ServicePort, V1ServiceSpec
|
|||||||
from authentik.outposts.controllers.base import FIELD_MANAGER
|
from authentik.outposts.controllers.base import FIELD_MANAGER
|
||||||
from authentik.outposts.controllers.k8s.base import KubernetesObjectReconciler
|
from authentik.outposts.controllers.k8s.base import KubernetesObjectReconciler
|
||||||
from authentik.outposts.controllers.k8s.deployment import DeploymentReconciler
|
from authentik.outposts.controllers.k8s.deployment import DeploymentReconciler
|
||||||
|
from authentik.outposts.controllers.k8s.triggers import NeedsUpdate
|
||||||
from authentik.outposts.controllers.k8s.utils import compare_ports
|
from authentik.outposts.controllers.k8s.utils import compare_ports
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -25,6 +26,8 @@ class ServiceReconciler(KubernetesObjectReconciler[V1Service]):
|
|||||||
# after an authentik update. However the ports might have also changed during
|
# after an authentik update. However the ports might have also changed during
|
||||||
# the update, so this causes the service to be re-created with higher
|
# the update, so this causes the service to be re-created with higher
|
||||||
# priority than being updated.
|
# priority than being updated.
|
||||||
|
if current.spec.selector != reference.spec.selector:
|
||||||
|
raise NeedsUpdate()
|
||||||
super().reconcile(current, reference)
|
super().reconcile(current, reference)
|
||||||
|
|
||||||
def get_reference_object(self) -> V1Service:
|
def get_reference_object(self) -> V1Service:
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from kubernetes.client.models.v1_container_port import V1ContainerPort
|
from kubernetes.client.models.v1_container_port import V1ContainerPort
|
||||||
|
from kubernetes.client.models.v1_service_port import V1ServicePort
|
||||||
from kubernetes.config.incluster_config import SERVICE_TOKEN_FILENAME
|
from kubernetes.config.incluster_config import SERVICE_TOKEN_FILENAME
|
||||||
|
|
||||||
from authentik.outposts.controllers.k8s.triggers import NeedsRecreate
|
from authentik.outposts.controllers.k8s.triggers import NeedsRecreate
|
||||||
@ -16,10 +17,31 @@ def get_namespace() -> str:
|
|||||||
return "default"
|
return "default"
|
||||||
|
|
||||||
|
|
||||||
def compare_ports(current: list[V1ContainerPort], reference: list[V1ContainerPort]):
|
def compare_port(
|
||||||
|
current: V1ServicePort | V1ContainerPort, reference: V1ServicePort | V1ContainerPort
|
||||||
|
) -> bool:
|
||||||
|
"""Compare a single port"""
|
||||||
|
if current.name != reference.name:
|
||||||
|
return False
|
||||||
|
if current.protocol != reference.protocol:
|
||||||
|
return False
|
||||||
|
if isinstance(current, V1ServicePort) and isinstance(reference, V1ServicePort):
|
||||||
|
# We only care about the target port
|
||||||
|
if current.target_port != reference.target_port:
|
||||||
|
return False
|
||||||
|
if isinstance(current, V1ContainerPort) and isinstance(reference, V1ContainerPort):
|
||||||
|
# We only care about the target port
|
||||||
|
if current.container_port != reference.container_port:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def compare_ports(
|
||||||
|
current: list[V1ServicePort | V1ContainerPort], reference: list[V1ServicePort | V1ContainerPort]
|
||||||
|
):
|
||||||
"""Compare ports of a list"""
|
"""Compare ports of a list"""
|
||||||
if len(current) != len(reference):
|
if len(current) != len(reference):
|
||||||
raise NeedsRecreate()
|
raise NeedsRecreate()
|
||||||
for port in reference:
|
for port in reference:
|
||||||
if port not in current:
|
if not any(compare_port(port, current_port) for current_port in current):
|
||||||
raise NeedsRecreate()
|
raise NeedsRecreate()
|
||||||
|
@ -1,34 +1,67 @@
|
|||||||
"""Kubernetes deployment controller"""
|
"""Kubernetes deployment controller"""
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from typing import Type
|
|
||||||
|
|
||||||
|
from kubernetes.client import VersionApi, VersionInfo
|
||||||
from kubernetes.client.api_client import ApiClient
|
from kubernetes.client.api_client import ApiClient
|
||||||
|
from kubernetes.client.configuration import Configuration
|
||||||
from kubernetes.client.exceptions import OpenApiException
|
from kubernetes.client.exceptions import OpenApiException
|
||||||
|
from kubernetes.config.config_exception import ConfigException
|
||||||
|
from kubernetes.config.incluster_config import load_incluster_config
|
||||||
|
from kubernetes.config.kube_config import load_kube_config_from_dict
|
||||||
from structlog.testing import capture_logs
|
from structlog.testing import capture_logs
|
||||||
from urllib3.exceptions import HTTPError
|
from urllib3.exceptions import HTTPError
|
||||||
from yaml import dump_all
|
from yaml import dump_all
|
||||||
|
|
||||||
from authentik.outposts.controllers.base import BaseController, ControllerException
|
from authentik.outposts.controllers.base import BaseClient, BaseController, ControllerException
|
||||||
from authentik.outposts.controllers.k8s.base import KubernetesObjectReconciler
|
from authentik.outposts.controllers.k8s.base import KubernetesObjectReconciler
|
||||||
from authentik.outposts.controllers.k8s.deployment import DeploymentReconciler
|
from authentik.outposts.controllers.k8s.deployment import DeploymentReconciler
|
||||||
from authentik.outposts.controllers.k8s.secret import SecretReconciler
|
from authentik.outposts.controllers.k8s.secret import SecretReconciler
|
||||||
from authentik.outposts.controllers.k8s.service import ServiceReconciler
|
from authentik.outposts.controllers.k8s.service import ServiceReconciler
|
||||||
from authentik.outposts.controllers.k8s.service_monitor import PrometheusServiceMonitorReconciler
|
from authentik.outposts.controllers.k8s.service_monitor import PrometheusServiceMonitorReconciler
|
||||||
from authentik.outposts.models import KubernetesServiceConnection, Outpost, ServiceConnectionInvalid
|
from authentik.outposts.models import (
|
||||||
|
KubernetesServiceConnection,
|
||||||
|
Outpost,
|
||||||
|
OutpostServiceConnectionState,
|
||||||
|
ServiceConnectionInvalid,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class KubernetesClient(ApiClient, BaseClient):
|
||||||
|
"""Custom kubernetes client based on service connection"""
|
||||||
|
|
||||||
|
def __init__(self, connection: KubernetesServiceConnection):
|
||||||
|
config = Configuration()
|
||||||
|
try:
|
||||||
|
if connection.local:
|
||||||
|
load_incluster_config(client_configuration=config)
|
||||||
|
else:
|
||||||
|
load_kube_config_from_dict(connection.kubeconfig, client_configuration=config)
|
||||||
|
super().__init__(config)
|
||||||
|
except ConfigException as exc:
|
||||||
|
raise ServiceConnectionInvalid from exc
|
||||||
|
|
||||||
|
def fetch_state(self) -> OutpostServiceConnectionState:
|
||||||
|
"""Get version info"""
|
||||||
|
try:
|
||||||
|
api_instance = VersionApi(self)
|
||||||
|
version: VersionInfo = api_instance.get_code()
|
||||||
|
return OutpostServiceConnectionState(version=version.git_version, healthy=True)
|
||||||
|
except (OpenApiException, HTTPError, ServiceConnectionInvalid):
|
||||||
|
return OutpostServiceConnectionState(version="", healthy=False)
|
||||||
|
|
||||||
|
|
||||||
class KubernetesController(BaseController):
|
class KubernetesController(BaseController):
|
||||||
"""Manage deployment of outpost in kubernetes"""
|
"""Manage deployment of outpost in kubernetes"""
|
||||||
|
|
||||||
reconcilers: dict[str, Type[KubernetesObjectReconciler]]
|
reconcilers: dict[str, type[KubernetesObjectReconciler]]
|
||||||
reconcile_order: list[str]
|
reconcile_order: list[str]
|
||||||
|
|
||||||
client: ApiClient
|
client: KubernetesClient
|
||||||
connection: KubernetesServiceConnection
|
connection: KubernetesServiceConnection
|
||||||
|
|
||||||
def __init__(self, outpost: Outpost, connection: KubernetesServiceConnection) -> None:
|
def __init__(self, outpost: Outpost, connection: KubernetesServiceConnection) -> None:
|
||||||
super().__init__(outpost, connection)
|
super().__init__(outpost, connection)
|
||||||
self.client = connection.client()
|
self.client = KubernetesClient(connection)
|
||||||
self.reconcilers = {
|
self.reconcilers = {
|
||||||
"secret": SecretReconciler,
|
"secret": SecretReconciler,
|
||||||
"deployment": DeploymentReconciler,
|
"deployment": DeploymentReconciler,
|
||||||
|
86
authentik/outposts/docker_ssh.py
Normal file
86
authentik/outposts/docker_ssh.py
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
"""Docker SSH helper"""
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
from tempfile import gettempdir
|
||||||
|
|
||||||
|
from docker.errors import DockerException
|
||||||
|
|
||||||
|
from authentik.crypto.models import CertificateKeyPair
|
||||||
|
|
||||||
|
HEADER = "### Managed by authentik"
|
||||||
|
FOOTER = "### End Managed by authentik"
|
||||||
|
|
||||||
|
|
||||||
|
def opener(path, flags):
|
||||||
|
"""File opener to create files as 700 perms"""
|
||||||
|
return os.open(path, flags, 0o700)
|
||||||
|
|
||||||
|
|
||||||
|
class DockerInlineSSH:
|
||||||
|
"""Create paramiko ssh config from CertificateKeyPair"""
|
||||||
|
|
||||||
|
host: str
|
||||||
|
keypair: CertificateKeyPair
|
||||||
|
|
||||||
|
key_path: str
|
||||||
|
config_path: Path
|
||||||
|
header: str
|
||||||
|
|
||||||
|
def __init__(self, host: str, keypair: CertificateKeyPair) -> None:
|
||||||
|
self.host = host
|
||||||
|
self.keypair = keypair
|
||||||
|
if not self.keypair:
|
||||||
|
raise DockerException("keypair must be set for SSH connections")
|
||||||
|
self.config_path = Path("~/.ssh/config").expanduser()
|
||||||
|
self.header = f"{HEADER} - {self.host}\n"
|
||||||
|
|
||||||
|
def write_config(self, key_path: str) -> bool:
|
||||||
|
"""Update the local user's ssh config file"""
|
||||||
|
with open(self.config_path, "a+", encoding="utf-8") as ssh_config:
|
||||||
|
if self.header in ssh_config.readlines():
|
||||||
|
return False
|
||||||
|
ssh_config.writelines(
|
||||||
|
[
|
||||||
|
self.header,
|
||||||
|
f"Host {self.host}\n",
|
||||||
|
f" IdentityFile {key_path}\n",
|
||||||
|
f"{FOOTER}\n",
|
||||||
|
"\n",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def write_key(self):
|
||||||
|
"""Write keypair's private key to a temporary file"""
|
||||||
|
path = Path(gettempdir(), f"{self.keypair.pk}_private.pem")
|
||||||
|
with open(path, "w", encoding="utf8", opener=opener) as _file:
|
||||||
|
_file.write(self.keypair.key_data)
|
||||||
|
return str(path)
|
||||||
|
|
||||||
|
def write(self):
|
||||||
|
"""Write keyfile and update ssh config"""
|
||||||
|
self.key_path = self.write_key()
|
||||||
|
was_written = self.write_config(self.key_path)
|
||||||
|
if not was_written:
|
||||||
|
self.cleanup()
|
||||||
|
|
||||||
|
def cleanup(self):
|
||||||
|
"""Cleanup when we're done"""
|
||||||
|
try:
|
||||||
|
os.unlink(self.key_path)
|
||||||
|
with open(self.config_path, "r+", encoding="utf-8") as ssh_config:
|
||||||
|
start = 0
|
||||||
|
end = 0
|
||||||
|
lines = ssh_config.readlines()
|
||||||
|
for idx, line in enumerate(lines):
|
||||||
|
if line == self.header:
|
||||||
|
start = idx
|
||||||
|
if start != 0 and line == f"{FOOTER}\n":
|
||||||
|
end = idx
|
||||||
|
with open(self.config_path, "w+", encoding="utf-8") as ssh_config:
|
||||||
|
lines = lines[:start] + lines[end + 2 :]
|
||||||
|
ssh_config.writelines(lines)
|
||||||
|
except OSError:
|
||||||
|
# If we fail deleting a file it doesn't matter that much
|
||||||
|
# since we're just in a container
|
||||||
|
pass
|
@ -1,4 +1,5 @@
|
|||||||
"""Create Docker TLSConfig from CertificateKeyPair"""
|
"""Create Docker TLSConfig from CertificateKeyPair"""
|
||||||
|
from os import unlink
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from tempfile import gettempdir
|
from tempfile import gettempdir
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
@ -14,6 +15,8 @@ class DockerInlineTLS:
|
|||||||
verification_kp: Optional[CertificateKeyPair]
|
verification_kp: Optional[CertificateKeyPair]
|
||||||
authentication_kp: Optional[CertificateKeyPair]
|
authentication_kp: Optional[CertificateKeyPair]
|
||||||
|
|
||||||
|
_paths: list[str]
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
verification_kp: Optional[CertificateKeyPair],
|
verification_kp: Optional[CertificateKeyPair],
|
||||||
@ -21,14 +24,21 @@ class DockerInlineTLS:
|
|||||||
) -> None:
|
) -> None:
|
||||||
self.verification_kp = verification_kp
|
self.verification_kp = verification_kp
|
||||||
self.authentication_kp = authentication_kp
|
self.authentication_kp = authentication_kp
|
||||||
|
self._paths = []
|
||||||
|
|
||||||
def write_file(self, name: str, contents: str) -> str:
|
def write_file(self, name: str, contents: str) -> str:
|
||||||
"""Wrapper for mkstemp that uses fdopen"""
|
"""Wrapper for mkstemp that uses fdopen"""
|
||||||
path = Path(gettempdir(), name)
|
path = Path(gettempdir(), name)
|
||||||
with open(path, "w", encoding="utf8") as _file:
|
with open(path, "w", encoding="utf8") as _file:
|
||||||
_file.write(contents)
|
_file.write(contents)
|
||||||
|
self._paths.append(str(path))
|
||||||
return str(path)
|
return str(path)
|
||||||
|
|
||||||
|
def cleanup(self):
|
||||||
|
"""Clean up certificates when we're done"""
|
||||||
|
for path in self._paths:
|
||||||
|
unlink(path)
|
||||||
|
|
||||||
def write(self) -> TLSConfig:
|
def write(self) -> TLSConfig:
|
||||||
"""Create TLSConfig with Certificate Key pairs"""
|
"""Create TLSConfig with Certificate Key pairs"""
|
||||||
# So yes, this is quite ugly. But sadly, there is no clean way to pass
|
# So yes, this is quite ugly. But sadly, there is no clean way to pass
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
"""Outpost models"""
|
"""Outpost models"""
|
||||||
from dataclasses import asdict, dataclass, field
|
from dataclasses import asdict, dataclass, field
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from os import environ
|
from typing import Iterable, Optional
|
||||||
from typing import Iterable, Optional, Union
|
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from dacite import from_dict
|
from dacite import from_dict
|
||||||
@ -11,23 +10,13 @@ from django.core.cache import cache
|
|||||||
from django.db import IntegrityError, models, transaction
|
from django.db import IntegrityError, models, transaction
|
||||||
from django.db.models.base import Model
|
from django.db.models.base import Model
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from docker.client import DockerClient
|
|
||||||
from docker.errors import DockerException
|
|
||||||
from guardian.models import UserObjectPermission
|
from guardian.models import UserObjectPermission
|
||||||
from guardian.shortcuts import assign_perm
|
from guardian.shortcuts import assign_perm
|
||||||
from kubernetes.client import VersionApi, VersionInfo
|
|
||||||
from kubernetes.client.api_client import ApiClient
|
|
||||||
from kubernetes.client.configuration import Configuration
|
|
||||||
from kubernetes.client.exceptions import OpenApiException
|
|
||||||
from kubernetes.config.config_exception import ConfigException
|
|
||||||
from kubernetes.config.incluster_config import load_incluster_config
|
|
||||||
from kubernetes.config.kube_config import load_kube_config_from_dict
|
|
||||||
from model_utils.managers import InheritanceManager
|
from model_utils.managers import InheritanceManager
|
||||||
from packaging.version import LegacyVersion, Version, parse
|
from packaging.version import LegacyVersion, Version, parse
|
||||||
from structlog.stdlib import get_logger
|
from structlog.stdlib import get_logger
|
||||||
from urllib3.exceptions import HTTPError
|
|
||||||
|
|
||||||
from authentik import ENV_GIT_HASH_KEY, __version__
|
from authentik import __version__, get_build_hash
|
||||||
from authentik.core.models import (
|
from authentik.core.models import (
|
||||||
USER_ATTRIBUTE_CAN_OVERRIDE_IP,
|
USER_ATTRIBUTE_CAN_OVERRIDE_IP,
|
||||||
USER_ATTRIBUTE_SA,
|
USER_ATTRIBUTE_SA,
|
||||||
@ -44,7 +33,6 @@ from authentik.lib.sentry import SentryIgnoredException
|
|||||||
from authentik.lib.utils.errors import exception_to_string
|
from authentik.lib.utils.errors import exception_to_string
|
||||||
from authentik.managed.models import ManagedModel
|
from authentik.managed.models import ManagedModel
|
||||||
from authentik.outposts.controllers.k8s.utils import get_namespace
|
from authentik.outposts.controllers.k8s.utils import get_namespace
|
||||||
from authentik.outposts.docker_tls import DockerInlineTLS
|
|
||||||
from authentik.tenants.models import Tenant
|
from authentik.tenants.models import Tenant
|
||||||
|
|
||||||
OUR_VERSION = parse(__version__)
|
OUR_VERSION = parse(__version__)
|
||||||
@ -72,6 +60,7 @@ class OutpostConfig:
|
|||||||
|
|
||||||
docker_network: Optional[str] = field(default=None)
|
docker_network: Optional[str] = field(default=None)
|
||||||
docker_map_ports: bool = field(default=True)
|
docker_map_ports: bool = field(default=True)
|
||||||
|
docker_labels: Optional[dict[str, str]] = field(default=None)
|
||||||
|
|
||||||
container_image: Optional[str] = field(default=None)
|
container_image: Optional[str] = field(default=None)
|
||||||
|
|
||||||
@ -87,7 +76,7 @@ class OutpostConfig:
|
|||||||
class OutpostModel(Model):
|
class OutpostModel(Model):
|
||||||
"""Base model for providers that need more objects than just themselves"""
|
"""Base model for providers that need more objects than just themselves"""
|
||||||
|
|
||||||
def get_required_objects(self) -> Iterable[Union[models.Model, str]]:
|
def get_required_objects(self) -> Iterable[models.Model | str]:
|
||||||
"""Return a list of all required objects"""
|
"""Return a list of all required objects"""
|
||||||
return [self]
|
return [self]
|
||||||
|
|
||||||
@ -150,10 +139,6 @@ class OutpostServiceConnection(models.Model):
|
|||||||
return OutpostServiceConnectionState("", False)
|
return OutpostServiceConnectionState("", False)
|
||||||
return state
|
return state
|
||||||
|
|
||||||
def fetch_state(self) -> OutpostServiceConnectionState:
|
|
||||||
"""Fetch current Service Connection state"""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def component(self) -> str:
|
def component(self) -> str:
|
||||||
"""Return component used to edit this object"""
|
"""Return component used to edit this object"""
|
||||||
@ -211,35 +196,6 @@ class DockerServiceConnection(OutpostServiceConnection):
|
|||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return f"Docker Service-Connection {self.name}"
|
return f"Docker Service-Connection {self.name}"
|
||||||
|
|
||||||
def client(self) -> DockerClient:
|
|
||||||
"""Get DockerClient"""
|
|
||||||
try:
|
|
||||||
client = None
|
|
||||||
if self.local:
|
|
||||||
client = DockerClient.from_env()
|
|
||||||
else:
|
|
||||||
client = DockerClient(
|
|
||||||
base_url=self.url,
|
|
||||||
tls=DockerInlineTLS(
|
|
||||||
verification_kp=self.tls_verification,
|
|
||||||
authentication_kp=self.tls_authentication,
|
|
||||||
).write(),
|
|
||||||
)
|
|
||||||
client.containers.list()
|
|
||||||
except DockerException as exc:
|
|
||||||
LOGGER.warning(exc)
|
|
||||||
raise ServiceConnectionInvalid from exc
|
|
||||||
return client
|
|
||||||
|
|
||||||
def fetch_state(self) -> OutpostServiceConnectionState:
|
|
||||||
try:
|
|
||||||
client = self.client()
|
|
||||||
return OutpostServiceConnectionState(
|
|
||||||
version=client.info()["ServerVersion"], healthy=True
|
|
||||||
)
|
|
||||||
except ServiceConnectionInvalid:
|
|
||||||
return OutpostServiceConnectionState(version="", healthy=False)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
||||||
verbose_name = _("Docker Service-Connection")
|
verbose_name = _("Docker Service-Connection")
|
||||||
@ -266,27 +222,6 @@ class KubernetesServiceConnection(OutpostServiceConnection):
|
|||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return f"Kubernetes Service-Connection {self.name}"
|
return f"Kubernetes Service-Connection {self.name}"
|
||||||
|
|
||||||
def fetch_state(self) -> OutpostServiceConnectionState:
|
|
||||||
try:
|
|
||||||
client = self.client()
|
|
||||||
api_instance = VersionApi(client)
|
|
||||||
version: VersionInfo = api_instance.get_code()
|
|
||||||
return OutpostServiceConnectionState(version=version.git_version, healthy=True)
|
|
||||||
except (OpenApiException, HTTPError, ServiceConnectionInvalid):
|
|
||||||
return OutpostServiceConnectionState(version="", healthy=False)
|
|
||||||
|
|
||||||
def client(self) -> ApiClient:
|
|
||||||
"""Get Kubernetes client configured from kubeconfig"""
|
|
||||||
config = Configuration()
|
|
||||||
try:
|
|
||||||
if self.local:
|
|
||||||
load_incluster_config(client_configuration=config)
|
|
||||||
else:
|
|
||||||
load_kube_config_from_dict(self.kubeconfig, client_configuration=config)
|
|
||||||
return ApiClient(config)
|
|
||||||
except ConfigException as exc:
|
|
||||||
raise ServiceConnectionInvalid from exc
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
||||||
verbose_name = _("Kubernetes Service-Connection")
|
verbose_name = _("Kubernetes Service-Connection")
|
||||||
@ -440,9 +375,9 @@ class Outpost(ManagedModel):
|
|||||||
Token.objects.filter(identifier=self.token_identifier).delete()
|
Token.objects.filter(identifier=self.token_identifier).delete()
|
||||||
return self.token
|
return self.token
|
||||||
|
|
||||||
def get_required_objects(self) -> Iterable[Union[models.Model, str]]:
|
def get_required_objects(self) -> Iterable[models.Model | str]:
|
||||||
"""Get an iterator of all objects the user needs read access to"""
|
"""Get an iterator of all objects the user needs read access to"""
|
||||||
objects: list[Union[models.Model, str]] = [
|
objects: list[models.Model | str] = [
|
||||||
self,
|
self,
|
||||||
"authentik_events.add_event",
|
"authentik_events.add_event",
|
||||||
]
|
]
|
||||||
@ -469,7 +404,7 @@ class OutpostState:
|
|||||||
channel_ids: list[str] = field(default_factory=list)
|
channel_ids: list[str] = field(default_factory=list)
|
||||||
last_seen: Optional[datetime] = field(default=None)
|
last_seen: Optional[datetime] = field(default=None)
|
||||||
version: Optional[str] = field(default=None)
|
version: Optional[str] = field(default=None)
|
||||||
version_should: Union[Version, LegacyVersion] = field(default=OUR_VERSION)
|
version_should: Version | LegacyVersion = field(default=OUR_VERSION)
|
||||||
build_hash: str = field(default="")
|
build_hash: str = field(default="")
|
||||||
|
|
||||||
_outpost: Optional[Outpost] = field(default=None)
|
_outpost: Optional[Outpost] = field(default=None)
|
||||||
@ -479,7 +414,7 @@ class OutpostState:
|
|||||||
"""Check if outpost version matches our version"""
|
"""Check if outpost version matches our version"""
|
||||||
if not self.version:
|
if not self.version:
|
||||||
return False
|
return False
|
||||||
if self.build_hash != environ.get(ENV_GIT_HASH_KEY, ""):
|
if self.build_hash != get_build_hash():
|
||||||
return False
|
return False
|
||||||
return parse(self.version) < OUR_VERSION
|
return parse(self.version) < OUR_VERSION
|
||||||
|
|
||||||
|
@ -23,8 +23,11 @@ from authentik.events.monitored_tasks import (
|
|||||||
TaskResultStatus,
|
TaskResultStatus,
|
||||||
prefill_task,
|
prefill_task,
|
||||||
)
|
)
|
||||||
|
from authentik.lib.config import CONFIG
|
||||||
from authentik.lib.utils.reflection import path_to_class
|
from authentik.lib.utils.reflection import path_to_class
|
||||||
from authentik.outposts.controllers.base import BaseController, ControllerException
|
from authentik.outposts.controllers.base import BaseController, ControllerException
|
||||||
|
from authentik.outposts.controllers.docker import DockerClient
|
||||||
|
from authentik.outposts.controllers.kubernetes import KubernetesClient
|
||||||
from authentik.outposts.models import (
|
from authentik.outposts.models import (
|
||||||
DockerServiceConnection,
|
DockerServiceConnection,
|
||||||
KubernetesServiceConnection,
|
KubernetesServiceConnection,
|
||||||
@ -45,21 +48,21 @@ LOGGER = get_logger()
|
|||||||
CACHE_KEY_OUTPOST_DOWN = "outpost_teardown_%s"
|
CACHE_KEY_OUTPOST_DOWN = "outpost_teardown_%s"
|
||||||
|
|
||||||
|
|
||||||
def controller_for_outpost(outpost: Outpost) -> Optional[BaseController]:
|
def controller_for_outpost(outpost: Outpost) -> Optional[type[BaseController]]:
|
||||||
"""Get a controller for the outpost, when a service connection is defined"""
|
"""Get a controller for the outpost, when a service connection is defined"""
|
||||||
if not outpost.service_connection:
|
if not outpost.service_connection:
|
||||||
return None
|
return None
|
||||||
service_connection = outpost.service_connection
|
service_connection = outpost.service_connection
|
||||||
if outpost.type == OutpostType.PROXY:
|
if outpost.type == OutpostType.PROXY:
|
||||||
if isinstance(service_connection, DockerServiceConnection):
|
if isinstance(service_connection, DockerServiceConnection):
|
||||||
return ProxyDockerController(outpost, service_connection)
|
return ProxyDockerController
|
||||||
if isinstance(service_connection, KubernetesServiceConnection):
|
if isinstance(service_connection, KubernetesServiceConnection):
|
||||||
return ProxyKubernetesController(outpost, service_connection)
|
return ProxyKubernetesController
|
||||||
if outpost.type == OutpostType.LDAP:
|
if outpost.type == OutpostType.LDAP:
|
||||||
if isinstance(service_connection, DockerServiceConnection):
|
if isinstance(service_connection, DockerServiceConnection):
|
||||||
return LDAPDockerController(outpost, service_connection)
|
return LDAPDockerController
|
||||||
if isinstance(service_connection, KubernetesServiceConnection):
|
if isinstance(service_connection, KubernetesServiceConnection):
|
||||||
return LDAPKubernetesController(outpost, service_connection)
|
return LDAPKubernetesController
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@ -71,7 +74,16 @@ def outpost_service_connection_state(connection_pk: Any):
|
|||||||
)
|
)
|
||||||
if not connection:
|
if not connection:
|
||||||
return
|
return
|
||||||
state = connection.fetch_state()
|
if isinstance(connection, DockerServiceConnection):
|
||||||
|
cls = DockerClient
|
||||||
|
if isinstance(connection, KubernetesServiceConnection):
|
||||||
|
cls = KubernetesClient
|
||||||
|
try:
|
||||||
|
with cls(connection) as client:
|
||||||
|
state = client.fetch_state()
|
||||||
|
except ServiceConnectionInvalid as exc:
|
||||||
|
LOGGER.warning("Failed to get client status", exc=exc)
|
||||||
|
return
|
||||||
cache.set(connection.state_key, state, timeout=None)
|
cache.set(connection.state_key, state, timeout=None)
|
||||||
|
|
||||||
|
|
||||||
@ -114,14 +126,15 @@ def outpost_controller(
|
|||||||
return
|
return
|
||||||
self.set_uid(slugify(outpost.name))
|
self.set_uid(slugify(outpost.name))
|
||||||
try:
|
try:
|
||||||
controller = controller_for_outpost(outpost)
|
controller_type = controller_for_outpost(outpost)
|
||||||
if not controller:
|
if not controller_type:
|
||||||
return
|
return
|
||||||
logs = getattr(controller, f"{action}_with_logs")()
|
with controller_type(outpost, outpost.service_connection) as controller:
|
||||||
LOGGER.debug("---------------Outpost Controller logs starting----------------")
|
logs = getattr(controller, f"{action}_with_logs")()
|
||||||
for log in logs:
|
LOGGER.debug("---------------Outpost Controller logs starting----------------")
|
||||||
LOGGER.debug(log)
|
for log in logs:
|
||||||
LOGGER.debug("-----------------Outpost Controller logs end-------------------")
|
LOGGER.debug(log)
|
||||||
|
LOGGER.debug("-----------------Outpost Controller logs end-------------------")
|
||||||
except (ControllerException, ServiceConnectionInvalid) as exc:
|
except (ControllerException, ServiceConnectionInvalid) as exc:
|
||||||
self.set_status(TaskResult(TaskResultStatus.ERROR).with_error(exc))
|
self.set_status(TaskResult(TaskResultStatus.ERROR).with_error(exc))
|
||||||
else:
|
else:
|
||||||
@ -219,6 +232,9 @@ def _outpost_single_update(outpost: Outpost, layer=None):
|
|||||||
@CELERY_APP.task()
|
@CELERY_APP.task()
|
||||||
def outpost_local_connection():
|
def outpost_local_connection():
|
||||||
"""Checks the local environment and create Service connections."""
|
"""Checks the local environment and create Service connections."""
|
||||||
|
if not CONFIG.y_bool("outposts.discover"):
|
||||||
|
LOGGER.debug("outpost integration discovery is disabled")
|
||||||
|
return
|
||||||
# Explicitly check against token filename, as that's
|
# Explicitly check against token filename, as that's
|
||||||
# only present when the integration is enabled
|
# only present when the integration is enabled
|
||||||
if Path(SERVICE_TOKEN_FILENAME).exists():
|
if Path(SERVICE_TOKEN_FILENAME).exists():
|
||||||
|
@ -5,7 +5,7 @@ from typing import Iterator, Optional
|
|||||||
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
from prometheus_client import Histogram
|
from prometheus_client import Gauge, Histogram
|
||||||
from sentry_sdk.hub import Hub
|
from sentry_sdk.hub import Hub
|
||||||
from sentry_sdk.tracing import Span
|
from sentry_sdk.tracing import Span
|
||||||
from structlog.stdlib import BoundLogger, get_logger
|
from structlog.stdlib import BoundLogger, get_logger
|
||||||
@ -14,13 +14,11 @@ from authentik.core.models import User
|
|||||||
from authentik.policies.models import Policy, PolicyBinding, PolicyBindingModel, PolicyEngineMode
|
from authentik.policies.models import Policy, PolicyBinding, PolicyBindingModel, PolicyEngineMode
|
||||||
from authentik.policies.process import PolicyProcess, cache_key
|
from authentik.policies.process import PolicyProcess, cache_key
|
||||||
from authentik.policies.types import PolicyRequest, PolicyResult
|
from authentik.policies.types import PolicyRequest, PolicyResult
|
||||||
from authentik.root.monitoring import UpdatingGauge
|
|
||||||
|
|
||||||
CURRENT_PROCESS = current_process()
|
CURRENT_PROCESS = current_process()
|
||||||
GAUGE_POLICIES_CACHED = UpdatingGauge(
|
GAUGE_POLICIES_CACHED = Gauge(
|
||||||
"authentik_policies_cached",
|
"authentik_policies_cached",
|
||||||
"Cached Policies",
|
"Cached Policies",
|
||||||
update_func=lambda: len(cache.keys("policy_*") or []),
|
|
||||||
)
|
)
|
||||||
HIST_POLICIES_BUILD_TIME = Histogram(
|
HIST_POLICIES_BUILD_TIME = Histogram(
|
||||||
"authentik_policies_build_time",
|
"authentik_policies_build_time",
|
||||||
|
@ -45,7 +45,7 @@ class HaveIBeenPwendPolicy(Policy):
|
|||||||
fields=request.context.keys(),
|
fields=request.context.keys(),
|
||||||
)
|
)
|
||||||
return PolicyResult(False, _("Password not set in context"))
|
return PolicyResult(False, _("Password not set in context"))
|
||||||
password = request.context[self.password_field]
|
password = str(request.context[self.password_field])
|
||||||
|
|
||||||
pw_hash = sha1(password.encode("utf-8")).hexdigest() # nosec
|
pw_hash = sha1(password.encode("utf-8")).hexdigest() # nosec
|
||||||
url = f"https://api.pwnedpasswords.com/range/{pw_hash[:5]}"
|
url = f"https://api.pwnedpasswords.com/range/{pw_hash[:5]}"
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
"""Password flow tests"""
|
"""Password flow tests"""
|
||||||
from django.urls.base import reverse
|
from django.urls.base import reverse
|
||||||
from django.utils.encoding import force_str
|
|
||||||
from rest_framework.test import APITestCase
|
|
||||||
|
|
||||||
from authentik.core.models import User
|
from authentik.core.models import User
|
||||||
from authentik.flows.challenge import ChallengeTypes
|
|
||||||
from authentik.flows.models import Flow, FlowDesignation, FlowStageBinding
|
from authentik.flows.models import Flow, FlowDesignation, FlowStageBinding
|
||||||
|
from authentik.flows.tests import FlowTestCase
|
||||||
from authentik.policies.password.models import PasswordPolicy
|
from authentik.policies.password.models import PasswordPolicy
|
||||||
from authentik.stages.prompt.models import FieldTypes, Prompt, PromptStage
|
from authentik.stages.prompt.models import FieldTypes, Prompt, PromptStage
|
||||||
|
|
||||||
|
|
||||||
class TestPasswordPolicyFlow(APITestCase):
|
class TestPasswordPolicyFlow(FlowTestCase):
|
||||||
"""Test Password Policy"""
|
"""Test Password Policy"""
|
||||||
|
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
@ -53,29 +51,22 @@ class TestPasswordPolicyFlow(APITestCase):
|
|||||||
{"password": "akadmin"},
|
{"password": "akadmin"},
|
||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertJSONEqual(
|
self.assertStageResponse(
|
||||||
force_str(response.content),
|
response,
|
||||||
{
|
self.flow,
|
||||||
"component": "ak-stage-prompt",
|
component="ak-stage-prompt",
|
||||||
"fields": [
|
fields=[
|
||||||
{
|
{
|
||||||
"field_key": "password",
|
"field_key": "password",
|
||||||
"label": "PASSWORD_LABEL",
|
"label": "PASSWORD_LABEL",
|
||||||
"order": 0,
|
"order": 0,
|
||||||
"placeholder": "PASSWORD_PLACEHOLDER",
|
"placeholder": "PASSWORD_PLACEHOLDER",
|
||||||
"required": True,
|
"required": True,
|
||||||
"type": "password",
|
"type": "password",
|
||||||
"sub_text": "",
|
"sub_text": "",
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"flow_info": {
|
response_errors={
|
||||||
"background": self.flow.background_url,
|
"non_field_errors": [{"code": "invalid", "string": self.policy.error_message}]
|
||||||
"cancel_url": reverse("authentik_flows:cancel"),
|
|
||||||
"title": "",
|
|
||||||
},
|
|
||||||
"response_errors": {
|
|
||||||
"non_field_errors": [{"code": "invalid", "string": self.policy.error_message}]
|
|
||||||
},
|
|
||||||
"type": ChallengeTypes.NATIVE.value,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
"""Source API Views"""
|
"""Reputation policy API Views"""
|
||||||
from rest_framework import mixins
|
from rest_framework import mixins
|
||||||
from rest_framework.serializers import ModelSerializer
|
from rest_framework.serializers import ModelSerializer
|
||||||
from rest_framework.viewsets import GenericViewSet, ModelViewSet
|
from rest_framework.viewsets import GenericViewSet, ModelViewSet
|
||||||
|
|
||||||
from authentik.core.api.used_by import UsedByMixin
|
from authentik.core.api.used_by import UsedByMixin
|
||||||
from authentik.policies.api.policies import PolicySerializer
|
from authentik.policies.api.policies import PolicySerializer
|
||||||
from authentik.policies.reputation.models import IPReputation, ReputationPolicy, UserReputation
|
from authentik.policies.reputation.models import Reputation, ReputationPolicy
|
||||||
|
|
||||||
|
|
||||||
class ReputationPolicySerializer(PolicySerializer):
|
class ReputationPolicySerializer(PolicySerializer):
|
||||||
@ -29,59 +29,32 @@ class ReputationPolicyViewSet(UsedByMixin, ModelViewSet):
|
|||||||
ordering = ["name"]
|
ordering = ["name"]
|
||||||
|
|
||||||
|
|
||||||
class IPReputationSerializer(ModelSerializer):
|
class ReputationSerializer(ModelSerializer):
|
||||||
"""IPReputation Serializer"""
|
"""Reputation Serializer"""
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = IPReputation
|
model = Reputation
|
||||||
fields = [
|
fields = [
|
||||||
"pk",
|
"pk",
|
||||||
|
"identifier",
|
||||||
"ip",
|
"ip",
|
||||||
|
"ip_geo_data",
|
||||||
"score",
|
"score",
|
||||||
"updated",
|
"updated",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class IPReputationViewSet(
|
class ReputationViewSet(
|
||||||
mixins.RetrieveModelMixin,
|
mixins.RetrieveModelMixin,
|
||||||
mixins.DestroyModelMixin,
|
mixins.DestroyModelMixin,
|
||||||
UsedByMixin,
|
UsedByMixin,
|
||||||
mixins.ListModelMixin,
|
mixins.ListModelMixin,
|
||||||
GenericViewSet,
|
GenericViewSet,
|
||||||
):
|
):
|
||||||
"""IPReputation Viewset"""
|
"""Reputation Viewset"""
|
||||||
|
|
||||||
queryset = IPReputation.objects.all()
|
queryset = Reputation.objects.all()
|
||||||
serializer_class = IPReputationSerializer
|
serializer_class = ReputationSerializer
|
||||||
search_fields = ["ip", "score"]
|
search_fields = ["identifier", "ip", "score"]
|
||||||
filterset_fields = ["ip", "score"]
|
filterset_fields = ["identifier", "ip", "score"]
|
||||||
ordering = ["ip"]
|
ordering = ["ip"]
|
||||||
|
|
||||||
|
|
||||||
class UserReputationSerializer(ModelSerializer):
|
|
||||||
"""UserReputation Serializer"""
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = UserReputation
|
|
||||||
fields = [
|
|
||||||
"pk",
|
|
||||||
"username",
|
|
||||||
"score",
|
|
||||||
"updated",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class UserReputationViewSet(
|
|
||||||
mixins.RetrieveModelMixin,
|
|
||||||
mixins.DestroyModelMixin,
|
|
||||||
UsedByMixin,
|
|
||||||
mixins.ListModelMixin,
|
|
||||||
GenericViewSet,
|
|
||||||
):
|
|
||||||
"""UserReputation Viewset"""
|
|
||||||
|
|
||||||
queryset = UserReputation.objects.all()
|
|
||||||
serializer_class = UserReputationSerializer
|
|
||||||
search_fields = ["username", "score"]
|
|
||||||
filterset_fields = ["username", "score"]
|
|
||||||
ordering = ["username"]
|
|
||||||
|
@ -13,3 +13,4 @@ class AuthentikPolicyReputationConfig(AppConfig):
|
|||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
import_module("authentik.policies.reputation.signals")
|
import_module("authentik.policies.reputation.signals")
|
||||||
|
import_module("authentik.policies.reputation.tasks")
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user