Compare commits
886 Commits
version/20
...
version-20
Author | SHA1 | Date | |
---|---|---|---|
5a7508d2e0 | |||
9c31ea1aa6 | |||
18211a2033 | |||
b4cfc56e5e | |||
8e797fa76b | |||
1b91543add | |||
1cd59be8dc | |||
66bb68a747 | |||
aa4f7fb2b6 | |||
4f1c11c5ef | |||
add7a80fdc | |||
aac91c2e9d | |||
85e86351cd | |||
d767504474 | |||
f84cd6208c | |||
1ec540ea9a | |||
29fe731bbf | |||
26e66969c9 | |||
fe629f8b51 | |||
72b7642c5a | |||
a97f842112 | |||
16e6e4c3b7 | |||
dc0d715885 | |||
7ecd57ecff | |||
0cb4d64b57 | |||
a4fd58a0db | |||
fb6e8ca1eb | |||
4c41948e75 | |||
a5c8caf909 | |||
970655ab21 | |||
c8c7202c61 | |||
a3981dd3cd | |||
affafc31cf | |||
602aed674b | |||
e6b515e3f7 | |||
36eaecfdec | |||
3973efae19 | |||
d8492e0df5 | |||
b64da0dd28 | |||
c3ae3e02f3 | |||
7c6a96394b | |||
0fe43f8319 | |||
7e32723748 | |||
577aa7ba79 | |||
b752540800 | |||
64c8ca9b5d | |||
5552e0ffa7 | |||
e7b7bfddd6 | |||
28f970c795 | |||
d1dbdfa9fe | |||
c4f4e3eac7 | |||
f21ebf5488 | |||
5615613ed1 | |||
669329e49c | |||
0587ab26e8 | |||
3c9cc9d421 | |||
1972464a20 | |||
3041a30193 | |||
1e28a1e311 | |||
5a1b912b76 | |||
464c27ef17 | |||
a745022f06 | |||
0b34f70205 | |||
a4b051fcc1 | |||
5ff3e9b418 | |||
8ae7403abc | |||
f6e1bfdfc8 | |||
aca3a5c458 | |||
d16c24fd53 | |||
6a8be0dc71 | |||
81b9b37e5e | |||
22b01962fb | |||
86cc99be35 | |||
416f917c4a | |||
f77bece790 | |||
a8dd846437 | |||
4c50769040 | |||
34189fcc06 | |||
fb5c8f3d7f | |||
049a55a761 | |||
4cd53f3d11 | |||
0d0dcf8de0 | |||
8cd1223081 | |||
1b4654bb1d | |||
0a3fade1fd | |||
ff64814f40 | |||
cbeb6e58ac | |||
285a9b8b1d | |||
66bfa6879d | |||
c05240afbf | |||
7370dd5f3f | |||
477c8b099e | |||
2c761da883 | |||
75070232b1 | |||
690b35e1a3 | |||
bd67f2362f | |||
896e5adce2 | |||
7f25b6311d | |||
253f345fc4 | |||
a3abbcec6a | |||
70e000d327 | |||
a7467e6740 | |||
b3da94bbb8 | |||
e62f5a75e4 | |||
39ad9d7c9d | |||
20d09c14b2 | |||
3a4d514bae | |||
4932846e14 | |||
bb62aa7c7f | |||
907b837301 | |||
b60a3d45dc | |||
3f5585ca84 | |||
ba9a4efc9b | |||
902378af53 | |||
2352a7f4d6 | |||
d89266a9d2 | |||
d678d33756 | |||
49d0ccd9c7 | |||
ea082ed9ef | |||
d62fc9766c | |||
983747b13b | |||
de4710ea71 | |||
d55b31dd82 | |||
d87871f806 | |||
148194e12b | |||
a2c587be43 | |||
673da2a96e | |||
a9a7b26264 | |||
83d2c442a5 | |||
4029e19b72 | |||
538a466090 | |||
322a343c81 | |||
6ddd6bfa72 | |||
36de302250 | |||
9eb13c50e9 | |||
cffc6a1b88 | |||
ba437beacc | |||
da32b05eba | |||
45b7e7565d | |||
a0b63f50bf | |||
dc5d571c99 | |||
05161db458 | |||
311ffa9f79 | |||
7cbe33d65d | |||
be9ca48de0 | |||
b3159a74e5 | |||
89fafff0af | |||
ae77c872a0 | |||
5f13563e03 | |||
e17c9040bb | |||
280ef3d265 | |||
a5bb583268 | |||
212ff11b6d | |||
1fa9d70945 | |||
eeeaa9317b | |||
09b932100f | |||
aa701c5725 | |||
6f98833150 | |||
30aa24ce6e | |||
a426a1a0b6 | |||
061c549a40 | |||
efa09d5e1d | |||
4fe0bd4b6c | |||
7c2decf5ec | |||
7f39399c32 | |||
7fd78a591d | |||
bdb84b7a8f | |||
84e9748340 | |||
7dfc621ae4 | |||
cd0a6f2d7c | |||
b7835a751b | |||
fd197ceee7 | |||
be5c8341d2 | |||
2036827f04 | |||
35665d248e | |||
bc30b41157 | |||
2af7fab42c | |||
4de205809b | |||
e8433472fd | |||
3896299312 | |||
5cfbb0993a | |||
a62e3557ac | |||
626936636a | |||
85ec713213 | |||
406bbdcfc9 | |||
02f87032cc | |||
b7a929d304 | |||
3c0cc27ea1 | |||
ec254d5927 | |||
92ba77e9e5 | |||
7ddb459030 | |||
076e89b600 | |||
ba5fa2a04f | |||
90fe1c2ce8 | |||
85f88e785f | |||
a7c4f81275 | |||
396fbc4a76 | |||
2dcd0128aa | |||
e5aa9e0774 | |||
53d78d561b | |||
93001d1329 | |||
40428f5a82 | |||
007838fcf2 | |||
5e03b27348 | |||
7c51afa36c | |||
38fd5c5614 | |||
7e3148fab5 | |||
948db46406 | |||
cccddd8c69 | |||
adc4cd9c0d | |||
abed254ca1 | |||
edfab0995f | |||
528dedf99d | |||
5d7eec3049 | |||
ad44567ebe | |||
ac82002339 | |||
df92111296 | |||
da8417a141 | |||
7f32355e3e | |||
5afe88a605 | |||
320dab3425 | |||
ca44f8bd60 | |||
5fd408ca82 | |||
becb9e34b5 | |||
4917ab9985 | |||
bd92505bc2 | |||
30033d1f90 | |||
3e5dfcbd0f | |||
bf0141acc6 | |||
0c8d513567 | |||
d07704fdf1 | |||
086a8753c0 | |||
ae7a6e2fd6 | |||
6a4ddcaba7 | |||
2c9b596f01 | |||
7257108091 | |||
91f7b289cc | |||
77a507d2f8 | |||
3e60e956f4 | |||
84ec70c2a2 | |||
72846f0ae1 | |||
dd53e7e9b1 | |||
9df16a9ae0 | |||
3dc9e247d5 | |||
02dd44eeec | |||
2f78e14381 | |||
ef6f692526 | |||
2dd575874b | |||
84c2ebabaa | |||
3e26170f4b | |||
4709dca33c | |||
6064a481fb | |||
3979b0bde7 | |||
4280847bcc | |||
ade8644da6 | |||
3c3fd53999 | |||
7b823f23ae | |||
a67bea95d4 | |||
775e0ef2fa | |||
d102c59654 | |||
03448a9169 | |||
1e6c081e5c | |||
8b9ce4a745 | |||
2a0bd50e23 | |||
014d93d485 | |||
ff42663d3c | |||
ce49d7ea5b | |||
8429dd19b2 | |||
680b182d95 | |||
b2a832175e | |||
b3ce8331f5 | |||
ef0f618234 | |||
b8a7186a55 | |||
b39530f873 | |||
7937c84f2b | |||
621843c60c | |||
c19da839b1 | |||
fea1f3be6f | |||
6f5ec7838f | |||
94300492e7 | |||
5d3931c128 | |||
262a8b5ae8 | |||
fe069c5e55 | |||
c6e60c0ebc | |||
90b457c5ee | |||
5e724e4299 | |||
b4c8dd6b91 | |||
63d163cc65 | |||
2b1356bb91 | |||
ba9edd6c44 | |||
3b2b3262d7 | |||
5431e7fe9d | |||
7d9c74ce04 | |||
60c3cf890a | |||
4ec5df6b12 | |||
0403f6d373 | |||
b7f4d15a94 | |||
56450887ca | |||
9bd613a31d | |||
3fe0483dbf | |||
63a28ca1e9 | |||
2543b075be | |||
b8bdf7a035 | |||
a3ff7cea23 | |||
bb776c2710 | |||
c9ad87d419 | |||
0d81eaffff | |||
6930c84425 | |||
eaaeaccf5d | |||
efbbd0adcf | |||
c8d9771640 | |||
1554dc9feb | |||
1005f341e4 | |||
2b98637ca5 | |||
e3f7185564 | |||
d1198fc6c1 | |||
8cb5f8fbee | |||
31a58e2c25 | |||
229715acb2 | |||
fad5b09aee | |||
2a670afd02 | |||
b69248dd55 | |||
5ff5edf769 | |||
939889e0ec | |||
19ae6585dc | |||
a81c847392 | |||
c6ede78fba | |||
cea1289186 | |||
c297f28552 | |||
35b25bd76e | |||
64d7610b13 | |||
2c8fcff832 | |||
054e76d02a | |||
80fa132dd9 | |||
4c59c3abef | |||
22d319c0e7 | |||
89edd77484 | |||
04e52d8ba6 | |||
9b5e3921cb | |||
2bbad64dc3 | |||
f6026fdb13 | |||
49def45ca3 | |||
a4856969f4 | |||
2aa7266688 | |||
25817cae6b | |||
5383ae2c19 | |||
c0c246edab | |||
831b32c279 | |||
70ccc63702 | |||
de954250e5 | |||
f268bd4c69 | |||
57a48b6350 | |||
9aac114115 | |||
66e3cbdc46 | |||
2d76d23f7b | |||
4327b35bc3 | |||
f7047df40e | |||
ef77a4b64e | |||
5d7d21076f | |||
ede072889e | |||
9cb7e6c606 | |||
e7d36c095d | |||
b88eb430c1 | |||
641872a33a | |||
405c690193 | |||
932cf48d2b | |||
402819107d | |||
41f135126b | |||
591a339302 | |||
35f2c5d96a | |||
fe6963c428 | |||
19cac4bf43 | |||
4ca564490e | |||
fcb795c273 | |||
14c70b3e4a | |||
ac880c28d7 | |||
f3c6b9a4f6 | |||
cba0cf0d76 | |||
73b67cf0f0 | |||
23a8052cc8 | |||
57c49c3865 | |||
cbea51ae5b | |||
8962081d92 | |||
e743f13f81 | |||
b20a8b7c17 | |||
b53c94d76a | |||
d4419d66c1 | |||
79044368d2 | |||
426686957d | |||
28cb803fd9 | |||
b98895ac2c | |||
85c3a36b62 | |||
6dc38b0132 | |||
e154e28611 | |||
690b7be1d8 | |||
9ba8a715b1 | |||
358750f66e | |||
b9918529b8 | |||
a5673b4ec8 | |||
d9287d0c0e | |||
d9c2b64116 | |||
2b150d3077 | |||
dec7a9cfb9 | |||
e0f48a30b7 | |||
973f14d911 | |||
e8978adc1b | |||
3ca8d9c968 | |||
42636142fa | |||
57c459348f | |||
493b34cf0d | |||
f0493f418b | |||
d45a292652 | |||
b21ea360db | |||
6816f8b851 | |||
de714f0390 | |||
800df332b5 | |||
16c194d2dc | |||
53100a72fe | |||
ec4c3f44cb | |||
f10bd432b3 | |||
4de927ba5b | |||
74e578c2bf | |||
e584fd1344 | |||
0e02925a3d | |||
5b837c3ccc | |||
2580371f94 | |||
4e9be85353 | |||
79508e1965 | |||
3a88dde545 | |||
31fc4d1cb9 | |||
09cd8f8f63 | |||
d824b09365 | |||
cabbd18880 | |||
c9dda17c68 | |||
bb8559ee18 | |||
5ae32e525c | |||
0832145a01 | |||
4167276c8f | |||
afb84c7bc5 | |||
82b2c7e3f0 | |||
fc8004db2b | |||
ddfc943bba | |||
8c0c12292e | |||
803490d98b | |||
16835ab478 | |||
572b8d87b5 | |||
31d2ea65fd | |||
f4ac2f50e2 | |||
969a3f0ddd | |||
4e18f47f28 | |||
f10286edf8 | |||
d789dcc28f | |||
715a71427e | |||
84c21d16cf | |||
2e4e17adb7 | |||
00cbaaf672 | |||
74e4e8f6aa | |||
d78fda990a | |||
10d949f7a9 | |||
6661af032d | |||
fb5e4a3af8 | |||
1dfad83a34 | |||
70025c648c | |||
676b77aa7c | |||
e35e096266 | |||
7af12d4fec | |||
8d6db0fabf | |||
8ddcf99bf7 | |||
e25f6aea8c | |||
b1a9eda1d3 | |||
2c15ab9995 | |||
b3c51e426d | |||
71578af47f | |||
6c985acb36 | |||
d878d2140e | |||
4766d6ff3d | |||
3a64d97040 | |||
2275ba3add | |||
9f7c941426 | |||
34ae9e6dab | |||
bf683514ee | |||
9b58bdb447 | |||
4237f20ccd | |||
2408719a47 | |||
b33fef7929 | |||
73b9847e7d | |||
a7e4eb021d | |||
11306770ad | |||
5235e00d3c | |||
7834146efc | |||
d4379ecd31 | |||
7492608ace | |||
7eef501446 | |||
b73de96aa6 | |||
a7adeb917e | |||
4ee2f951da | |||
01c5235e82 | |||
0ce4f9fe12 | |||
2f4f951818 | |||
a6c214e8fa | |||
57f8b108c4 | |||
7c1fe1243f | |||
3f69dd34ba | |||
c81431895a | |||
560c979d26 | |||
c5cc8842ec | |||
2a881d241d | |||
6291834573 | |||
eeea36acea | |||
e95b9da586 | |||
f4a53c89ef | |||
20493252e2 | |||
2210497569 | |||
2addf71f37 | |||
de11181890 | |||
66e3bc6b58 | |||
612679e8df | |||
c9072f7403 | |||
cacacb06af | |||
7da87a53b7 | |||
9f894881ca | |||
dad24c03ff | |||
fb8d67a9d9 | |||
029d58191e | |||
75404f1345 | |||
ba1b23c879 | |||
ae8cf00a21 | |||
d9ffb23a80 | |||
dab5f4c768 | |||
cd6632fca6 | |||
ea1741838c | |||
8256fa8c0b | |||
486a930163 | |||
8a58a31bd6 | |||
deb0d3f7bc | |||
10208b45b6 | |||
25f987ba2b | |||
f23111beff | |||
0f693158b6 | |||
e51226432f | |||
b1fbcef98a | |||
ce56192412 | |||
70d72f340f | |||
7524e114d9 | |||
4d7dab92bc | |||
a36e3aa3a4 | |||
fceab788d2 | |||
d55d44d664 | |||
88cc38394e | |||
ea1696a275 | |||
552d26eb98 | |||
90a5c84ac8 | |||
b55c3a687d | |||
e786244988 | |||
68f1fbebf4 | |||
9180d448df | |||
67470590c2 | |||
fe2e850303 | |||
a7a3c158ea | |||
98d0986ac8 | |||
bedf7fbcaa | |||
1f35f73c66 | |||
8ea02e4cc9 | |||
f399b32135 | |||
0032f535da | |||
3c349b1f22 | |||
17326615b7 | |||
f5dbdbd48b | |||
277c2f4aad | |||
d38f944435 | |||
ba3e0a0586 | |||
7581c84a37 | |||
86b450c6d1 | |||
e43e42139a | |||
0b90cfcec4 | |||
cefe3fa6dd | |||
24da24b5d5 | |||
f996f9d4e3 | |||
5411412626 | |||
f9050f9192 | |||
bc75c07e65 | |||
c02b943612 | |||
7b39718bd1 | |||
e9621bae06 | |||
0eaabbc0f3 | |||
5e3628bea6 | |||
290ebef8e3 | |||
46ab1d20df | |||
48e68d6852 | |||
cde056825e | |||
de25b64f2b | |||
32f0c6abe1 | |||
960210f351 | |||
7c300f0858 | |||
ed3859800c | |||
06b7f62a40 | |||
45b7c349f1 | |||
7bef6f7153 | |||
d32e40b1f8 | |||
cec47c3cfc | |||
4d773274d4 | |||
3ea2b16a12 | |||
974ddc07f7 | |||
2f64b76eba | |||
a113778ca7 | |||
06caaa7c80 | |||
b50ac96605 | |||
166b98fa34 | |||
6d0e0cbe5a | |||
b339452843 | |||
4f04ab7a5f | |||
35bcd5d174 | |||
644ff4a90c | |||
05d45383be | |||
702fdfedb7 | |||
2a0af8750d | |||
770316a49f | |||
85d349e776 | |||
f29344e91f | |||
9900cc5c81 | |||
3af48a81e2 | |||
5bebf26908 | |||
eea831fb5a | |||
2e4a9219a2 | |||
7f1098ce9b | |||
6cd6224d2b | |||
43d85f8696 | |||
ef8b26db13 | |||
ebfa7c8dce | |||
e295f18e78 | |||
cef5c2b084 | |||
e24a9e3119 | |||
264a170a7e | |||
8e1c2d7fc0 | |||
6c7f4197a1 | |||
1cd3866855 | |||
6a9c95c593 | |||
80adafdb48 | |||
72f5a4c460 | |||
fb6242d2d3 | |||
b9773d39c0 | |||
0e8d9aa45d | |||
fc45d35699 | |||
7e8044619c | |||
cf57660772 | |||
66a04aeec5 | |||
73338bdf32 | |||
059da74d1c | |||
45b8b1e198 | |||
5e43eb9838 | |||
11607622a3 | |||
133fc38c05 | |||
f51ab7a878 | |||
c89b8a5f7c | |||
31ad09c391 | |||
05b3c4ddb3 | |||
d52cc30341 | |||
d2e9683411 | |||
a4c28a28b4 | |||
6232333a52 | |||
a1203cf4b2 | |||
8427fb87f6 | |||
e3578eb7ae | |||
5990b8d4de | |||
3b31b7ce83 | |||
4d9b362dbf | |||
7bd93ed18e | |||
477ff85109 | |||
fae8b80ceb | |||
df92f01719 | |||
9dd6b7d436 | |||
14f85ec980 | |||
ff611f21cd | |||
a1b6e09e8a | |||
02b5742228 | |||
c5cc84c8b6 | |||
109ada570f | |||
b9436c281a | |||
89f2f920cf | |||
abd0d585a6 | |||
ee74281537 | |||
5488db3574 | |||
61f92095a5 | |||
3a9f081e1b | |||
a237ae3363 | |||
523621daa2 | |||
309d80a921 | |||
1bd41116a4 | |||
a7b85aeda2 | |||
142861e3ee | |||
02411bb543 | |||
c4453f38a2 | |||
250e23408e | |||
6f3eb4c068 | |||
58a4b20297 | |||
6d3e067a2b | |||
6db2bf2a21 | |||
6893948fa0 | |||
6317a8c5d0 | |||
bc39320f86 | |||
2001cf0e04 | |||
712c5df5b1 | |||
8057c63cb4 | |||
7816a3075a | |||
1679e94956 | |||
8ecac59eca | |||
af504e13a2 | |||
8183a51b72 | |||
ab25610643 | |||
127ebed5c6 | |||
716923e17a | |||
c6bb6709fd | |||
fb4e0723ee | |||
8ecacb319c | |||
2a5926608f | |||
763c3fcfe0 | |||
1b346866da | |||
25a88c17d1 | |||
6f6ae7831e | |||
0062872e18 | |||
e49fb3295f | |||
0e89353ac9 | |||
b8f98881fa | |||
f887850b95 | |||
2ec4b4ec98 | |||
c98e4196bd | |||
3b41c662ed | |||
65522186f1 | |||
9f5a3c396d | |||
53e2b2c784 | |||
a5cd9fa141 | |||
039a1e544e | |||
0768b201a7 | |||
c1c55a6005 | |||
0144e1ad72 | |||
2d5c45543b | |||
9b57f0b81d | |||
9d476a42d1 | |||
2c816e6162 | |||
934cfa483c | |||
50308510b4 | |||
dbcb4d46ba | |||
bb89b9b572 | |||
6600da7d98 | |||
1a0f72d0a8 | |||
a265dd54cc | |||
a603f42cc0 | |||
d9a788aac8 | |||
7c6185b581 | |||
41a1305555 | |||
75f252b530 | |||
c526e5fb9a | |||
7aa903d715 | |||
b826eb264e | |||
a9519a4a68 | |||
a4960064c9 | |||
94bddb9886 | |||
f38702f361 | |||
c49fac39b1 | |||
b3390f0ab4 | |||
7666c246c3 | |||
bf4cbb25fe | |||
a925418f60 | |||
ffd61d0e60 | |||
13cc33c39c | |||
71d112bdcf | |||
c58fe18b97 | |||
d2c06c40ea | |||
590c7f4c9d | |||
9a48c2fd9a | |||
be5a6c0310 | |||
92106ca4bf | |||
56f1204c9b | |||
f6f93640c5 | |||
b8c76eaf1c | |||
9dbbd4eff6 | |||
2908be5272 | |||
349a5b2d00 | |||
63e3667e82 | |||
92f2a82c03 | |||
dcf074650e | |||
1324ec5146 | |||
0f556fe8a3 | |||
19371dad65 | |||
acf1ad91d9 | |||
a74419214c | |||
7bd8110984 | |||
aa5623772c | |||
50ede4cc2c | |||
879ad27602 | |||
37a63d104f | |||
bc6aef7af2 | |||
2498e72f5d | |||
c61442c121 | |||
2d66837742 | |||
90e7fbe238 | |||
4447f737e8 | |||
c13c747263 | |||
cac23f2fa4 | |||
788ea46d8c | |||
c285c6b476 | |||
a7cf364e43 | |||
06dee5d5d8 | |||
3cf0f07baf | |||
e177ab33e0 | |||
9e7c9ae649 | |||
f016095891 | |||
5a465fbc36 | |||
7cd80a903a | |||
dd00351bc7 | |||
5fca7d11b8 | |||
0ff59636f7 | |||
c4751e4b59 | |||
e5ebe390d2 | |||
7f4bd27b85 | |||
b66626f9c4 | |||
a51a18f3a3 | |||
b13d6deda8 | |||
23123c43ee | |||
8ce918d527 | |||
626006725e | |||
f9ce41229d | |||
ae6a406b1d | |||
45c1a603e7 | |||
330219e76f | |||
583271d5ed | |||
176360fdd7 | |||
0db17b9729 | |||
9f9ee66cc4 | |||
ab2bd622a8 | |||
6bd27d27ec | |||
8d2a3b67b9 | |||
a5233f89b2 | |||
8b6292b3de | |||
cbed5a6522 | |||
589f806b7c | |||
07dc648470 | |||
41f6d3b6e7 | |||
ec8490e105 | |||
69668a2a05 | |||
d0f1daf025 | |||
d38fd603dd | |||
ba5374f6e1 | |||
7152d7ee01 | |||
ab07113530 | |||
a7d7b46747 | |||
dde1dabf97 | |||
1f05484e3c | |||
9a44088d2b | |||
b351ae12c5 | |||
759bf59780 | |||
10cb60f48e | |||
99be97206b | |||
ef9f08553c | |||
4fb71a6bdd | |||
3ab7588b73 | |||
cac1f242dc | |||
0bac738090 | |||
d0d3072c50 | |||
1324d03815 | |||
34e2bbc41d | |||
ea2dbb2f33 | |||
c55f2ad10a | |||
2cde40aeee | |||
a30b32fbbf | |||
1745306cc6 | |||
8925787a13 | |||
968b7ec17a | |||
6600d5bf69 | |||
a4278833d8 | |||
942905b9b1 | |||
81056c3889 | |||
36b694fc41 | |||
2d9f216658 | |||
8d7bb7da17 | |||
965db6eaf5 | |||
9bdd6f23a4 | |||
675ad7710c | |||
9939db13c3 | |||
03e134b296 | |||
465750276c | |||
9b13191646 | |||
634ea61b50 | |||
0fcb4936a2 | |||
934e62d5be | |||
c5e9197b19 |
@ -1,5 +1,5 @@
|
|||||||
[bumpversion]
|
[bumpversion]
|
||||||
current_version = 2021.5.1
|
current_version = 2021.7.3
|
||||||
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>.*)
|
||||||
@ -21,18 +21,16 @@ values =
|
|||||||
|
|
||||||
[bumpversion:file:docker-compose.yml]
|
[bumpversion:file:docker-compose.yml]
|
||||||
|
|
||||||
|
[bumpversion:file:schema.yml]
|
||||||
|
|
||||||
[bumpversion:file:.github/workflows/release.yml]
|
[bumpversion:file:.github/workflows/release.yml]
|
||||||
|
|
||||||
[bumpversion:file:authentik/__init__.py]
|
[bumpversion:file:authentik/__init__.py]
|
||||||
|
|
||||||
[bumpversion:file:internal/constants/constants.go]
|
[bumpversion:file:internal/constants/constants.go]
|
||||||
|
|
||||||
[bumpversion:file:outpost/pkg/version.go]
|
|
||||||
|
|
||||||
[bumpversion:file:web/src/constants.ts]
|
[bumpversion:file:web/src/constants.ts]
|
||||||
|
|
||||||
[bumpversion:file:web/nginx.conf]
|
|
||||||
|
|
||||||
[bumpversion:file:website/docs/outposts/manual-deploy-docker-compose.md]
|
[bumpversion:file:website/docs/outposts/manual-deploy-docker-compose.md]
|
||||||
|
|
||||||
[bumpversion:file:website/docs/outposts/manual-deploy-kubernetes.md]
|
[bumpversion:file:website/docs/outposts/manual-deploy-kubernetes.md]
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
env
|
env
|
||||||
helm
|
|
||||||
static
|
static
|
||||||
htmlcov
|
htmlcov
|
||||||
*.env.yml
|
*.env.yml
|
||||||
**/node_modules
|
**/node_modules
|
||||||
|
dist/**
|
||||||
|
build/**
|
||||||
|
build_docs/**
|
||||||
|
27
.github/ISSUE_TEMPLATE/question.md
vendored
Normal file
27
.github/ISSUE_TEMPLATE/question.md
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
name: Question
|
||||||
|
about: Ask a question about a feature or specific configuration
|
||||||
|
title: ''
|
||||||
|
labels: question
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe your question/**
|
||||||
|
A clear and concise description of what you're trying to do.
|
||||||
|
|
||||||
|
**Relevant infos**
|
||||||
|
i.e. Version of other software you're using, specifics of your setup
|
||||||
|
|
||||||
|
**Screenshots**
|
||||||
|
If applicable, add screenshots to help explain your problem.
|
||||||
|
|
||||||
|
**Logs**
|
||||||
|
Output of docker-compose logs or kubectl logs respectively
|
||||||
|
|
||||||
|
**Version and Deployment (please complete the following information):**
|
||||||
|
- authentik version: [e.g. 0.10.0-stable]
|
||||||
|
- Deployment: [e.g. docker-compose, helm]
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
10
.github/dependabot.yml
vendored
10
.github/dependabot.yml
vendored
@ -9,7 +9,7 @@ updates:
|
|||||||
assignees:
|
assignees:
|
||||||
- BeryJu
|
- BeryJu
|
||||||
- package-ecosystem: gomod
|
- package-ecosystem: gomod
|
||||||
directory: "/outpost"
|
directory: "/"
|
||||||
schedule:
|
schedule:
|
||||||
interval: daily
|
interval: daily
|
||||||
time: "04:00"
|
time: "04:00"
|
||||||
@ -48,11 +48,3 @@ updates:
|
|||||||
open-pull-requests-limit: 10
|
open-pull-requests-limit: 10
|
||||||
assignees:
|
assignees:
|
||||||
- BeryJu
|
- BeryJu
|
||||||
- package-ecosystem: docker
|
|
||||||
directory: "/outpost"
|
|
||||||
schedule:
|
|
||||||
interval: daily
|
|
||||||
time: "04:00"
|
|
||||||
open-pull-requests-limit: 10
|
|
||||||
assignees:
|
|
||||||
- BeryJu
|
|
||||||
|
19
.github/pull_request_template.md
vendored
Normal file
19
.github/pull_request_template.md
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<!--
|
||||||
|
👋 Hello there! Welcome.
|
||||||
|
|
||||||
|
Please check the [Contributing guidelines](https://github.com/goauthentik/authentik/blob/master/CONTRIBUTING.md#how-can-i-contribute).
|
||||||
|
-->
|
||||||
|
|
||||||
|
# Details
|
||||||
|
* **Does this resolve an issue?**
|
||||||
|
Resolves #
|
||||||
|
|
||||||
|
## Changes
|
||||||
|
### New Features
|
||||||
|
* Adds feature which does x, y, and z.
|
||||||
|
|
||||||
|
### Breaking Changes
|
||||||
|
* Adds breaking change which causes \<issue\>.
|
||||||
|
|
||||||
|
## Additional
|
||||||
|
Any further notes or comments you want to make.
|
14
.github/stale.yml
vendored
Normal file
14
.github/stale.yml
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# Number of days of inactivity before an issue becomes stale
|
||||||
|
daysUntilStale: 60
|
||||||
|
# Number of days of inactivity before a stale issue is closed
|
||||||
|
daysUntilClose: 7
|
||||||
|
# Issues with these labels will never be considered stale
|
||||||
|
exemptLabels:
|
||||||
|
- pinned
|
||||||
|
- security
|
||||||
|
- pr_wanted
|
||||||
|
# Comment to post when marking an issue as stale. Set to `false` to disable
|
||||||
|
markComment: >
|
||||||
|
This issue has been automatically marked as stale because it has not had
|
||||||
|
recent activity. It will be closed if no further activity occurs. Thank you
|
||||||
|
for your contributions.
|
85
.github/workflows/release.yml
vendored
85
.github/workflows/release.yml
vendored
@ -14,7 +14,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v1.1.0
|
uses: docker/setup-qemu-action@v1.2.0
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v1
|
||||||
- name: Docker Login Registry
|
- name: Docker Login Registry
|
||||||
@ -28,20 +28,26 @@ jobs:
|
|||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.repository_owner }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- name: prepare ts api client
|
|
||||||
run: |
|
|
||||||
docker run --rm -v $(pwd):/local openapitools/openapi-generator-cli generate -i /local/swagger.yaml -g typescript-fetch -o /local/web/api --additional-properties=typescriptThreePlus=true,supportsES6=true,npmName=authentik-api,npmVersion=1.0.0
|
|
||||||
- name: Building Docker Image
|
- name: Building Docker Image
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v2
|
||||||
with:
|
with:
|
||||||
push: ${{ github.event_name == 'release' }}
|
push: ${{ github.event_name == 'release' }}
|
||||||
tags: |
|
tags: |
|
||||||
beryju/authentik:2021.5.1,
|
beryju/authentik:2021.7.3,
|
||||||
beryju/authentik:latest,
|
beryju/authentik:latest,
|
||||||
ghcr.io/goauthentik/server:2021.5.1,
|
ghcr.io/goauthentik/server:2021.7.3,
|
||||||
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.7.3', '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-proxy:
|
build-proxy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@ -49,14 +55,8 @@ jobs:
|
|||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: "^1.15"
|
go-version: "^1.15"
|
||||||
- name: prepare go api client
|
|
||||||
run: |
|
|
||||||
cd outpost
|
|
||||||
go get -u github.com/go-swagger/go-swagger/cmd/swagger
|
|
||||||
swagger generate client -f ../swagger.yaml -A authentik -t pkg/
|
|
||||||
go build -v ./cmd/proxy/server.go
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v1.1.0
|
uses: docker/setup-qemu-action@v1.2.0
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v1
|
||||||
- name: Docker Login Registry
|
- name: Docker Login Registry
|
||||||
@ -75,13 +75,21 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
push: ${{ github.event_name == 'release' }}
|
push: ${{ github.event_name == 'release' }}
|
||||||
tags: |
|
tags: |
|
||||||
beryju/authentik-proxy:2021.5.1,
|
beryju/authentik-proxy:2021.7.3,
|
||||||
beryju/authentik-proxy:latest,
|
beryju/authentik-proxy:latest,
|
||||||
ghcr.io/goauthentik/proxy:2021.5.1,
|
ghcr.io/goauthentik/proxy:2021.7.3,
|
||||||
ghcr.io/goauthentik/proxy:latest
|
ghcr.io/goauthentik/proxy:latest
|
||||||
context: outpost/
|
file: proxy.Dockerfile
|
||||||
file: outpost/proxy.Dockerfile
|
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
|
- name: Building Docker Image (stable)
|
||||||
|
if: ${{ github.event_name == 'release' && !contains('2021.7.3', 'rc') }}
|
||||||
|
run: |
|
||||||
|
docker pull beryju/authentik-proxy:latest
|
||||||
|
docker tag beryju/authentik-proxy:latest beryju/authentik-proxy:stable
|
||||||
|
docker push beryju/authentik-proxy:stable
|
||||||
|
docker pull ghcr.io/goauthentik/proxy:latest
|
||||||
|
docker tag ghcr.io/goauthentik/proxy:latest ghcr.io/goauthentik/proxy:stable
|
||||||
|
docker push ghcr.io/goauthentik/proxy:stable
|
||||||
build-ldap:
|
build-ldap:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@ -89,14 +97,8 @@ jobs:
|
|||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: "^1.15"
|
go-version: "^1.15"
|
||||||
- name: prepare go api client
|
|
||||||
run: |
|
|
||||||
cd outpost
|
|
||||||
go get -u github.com/go-swagger/go-swagger/cmd/swagger
|
|
||||||
swagger generate client -f ../swagger.yaml -A authentik -t pkg/
|
|
||||||
go build -v ./cmd/ldap/server.go
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v1.1.0
|
uses: docker/setup-qemu-action@v1.2.0
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v1
|
||||||
- name: Docker Login Registry
|
- name: Docker Login Registry
|
||||||
@ -115,15 +117,22 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
push: ${{ github.event_name == 'release' }}
|
push: ${{ github.event_name == 'release' }}
|
||||||
tags: |
|
tags: |
|
||||||
beryju/authentik-ldap:2021.5.1,
|
beryju/authentik-ldap:2021.7.3,
|
||||||
beryju/authentik-ldap:latest,
|
beryju/authentik-ldap:latest,
|
||||||
ghcr.io/goauthentik/ldap:2021.5.1,
|
ghcr.io/goauthentik/ldap:2021.7.3,
|
||||||
ghcr.io/goauthentik/ldap:latest
|
ghcr.io/goauthentik/ldap:latest
|
||||||
context: outpost/
|
file: ldap.Dockerfile
|
||||||
file: outpost/ldap.Dockerfile
|
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
|
- name: Building Docker Image (stable)
|
||||||
|
if: ${{ github.event_name == 'release' && !contains('2021.7.3', 'rc') }}
|
||||||
|
run: |
|
||||||
|
docker pull beryju/authentik-ldap:latest
|
||||||
|
docker tag beryju/authentik-ldap:latest beryju/authentik-ldap:stable
|
||||||
|
docker push beryju/authentik-ldap:stable
|
||||||
|
docker pull ghcr.io/goauthentik/ldap:latest
|
||||||
|
docker tag ghcr.io/goauthentik/ldap:latest ghcr.io/goauthentik/ldap:stable
|
||||||
|
docker push ghcr.io/goauthentik/ldap:stable
|
||||||
test-release:
|
test-release:
|
||||||
if: ${{ github.event_name == 'release' }}
|
|
||||||
needs:
|
needs:
|
||||||
- build-server
|
- build-server
|
||||||
- build-proxy
|
- build-proxy
|
||||||
@ -139,7 +148,7 @@ jobs:
|
|||||||
docker-compose pull -q
|
docker-compose pull -q
|
||||||
docker-compose up --no-start
|
docker-compose up --no-start
|
||||||
docker-compose start postgresql redis
|
docker-compose start postgresql redis
|
||||||
docker-compose run -u root --entrypoint /bin/bash server -c "apt-get update && apt-get install -y --no-install-recommends git && pip install --no-cache -r requirements-dev.txt && ./manage.py test authentik"
|
docker-compose run -u root server test
|
||||||
sentry-release:
|
sentry-release:
|
||||||
if: ${{ github.event_name == 'release' }}
|
if: ${{ github.event_name == 'release' }}
|
||||||
needs:
|
needs:
|
||||||
@ -147,13 +156,27 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
- name: Setup Node.js environment
|
||||||
|
uses: actions/setup-node@v2.3.0
|
||||||
|
with:
|
||||||
|
node-version: 12.x
|
||||||
|
- name: Build web api client and web ui
|
||||||
|
run: |
|
||||||
|
export NODE_ENV=production
|
||||||
|
make gen-web
|
||||||
|
cd web
|
||||||
|
npm i
|
||||||
|
npm run build
|
||||||
- name: Create a Sentry.io release
|
- name: Create a Sentry.io release
|
||||||
uses: getsentry/action-release@v1
|
uses: getsentry/action-release@v1
|
||||||
|
if: ${{ github.event_name == 'release' }}
|
||||||
env:
|
env:
|
||||||
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
||||||
SENTRY_ORG: beryjuorg
|
SENTRY_ORG: beryjuorg
|
||||||
SENTRY_PROJECT: authentik
|
SENTRY_PROJECT: authentik
|
||||||
SENTRY_URL: https://sentry.beryju.org
|
SENTRY_URL: https://sentry.beryju.org
|
||||||
with:
|
with:
|
||||||
version: authentik@2021.5.1
|
version: authentik@2021.7.3
|
||||||
environment: beryjuorg-prod
|
environment: beryjuorg-prod
|
||||||
|
sourcemaps: './web/dist'
|
||||||
|
url_prefix: '~/static/dist'
|
||||||
|
7
.github/workflows/tag.yml
vendored
7
.github/workflows/tag.yml
vendored
@ -11,9 +11,6 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: prepare ts api client
|
|
||||||
run: |
|
|
||||||
docker run --rm -v $(pwd):/local openapitools/openapi-generator-cli generate -i /local/swagger.yaml -g typescript-fetch -o /local/web/api --additional-properties=typescriptThreePlus=true,supportsES6=true,npmName=authentik-api,npmVersion=1.0.0
|
|
||||||
- name: Pre-release test
|
- name: Pre-release test
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get install -y pwgen
|
sudo apt-get install -y pwgen
|
||||||
@ -23,11 +20,11 @@ jobs:
|
|||||||
docker-compose pull -q
|
docker-compose pull -q
|
||||||
docker build \
|
docker build \
|
||||||
--no-cache \
|
--no-cache \
|
||||||
-t beryju/authentik:latest \
|
-t ghcr.io/goauthentik/server:latest \
|
||||||
-f Dockerfile .
|
-f Dockerfile .
|
||||||
docker-compose up --no-start
|
docker-compose up --no-start
|
||||||
docker-compose start postgresql redis
|
docker-compose start postgresql redis
|
||||||
docker-compose run -u root --entrypoint /bin/bash server -c "apt-get update && apt-get install -y --no-install-recommends git && pip install --no-cache -r requirements-dev.txt && ./manage.py test authentik"
|
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@v4.0.2
|
uses: actions/github-script@v4.0.2
|
||||||
|
5
.gitignore
vendored
5
.gitignore
vendored
@ -193,10 +193,6 @@ pip-selfcheck.json
|
|||||||
local.env.yml
|
local.env.yml
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
### Helm ###
|
|
||||||
# Chart dependencies
|
|
||||||
**/charts/*.tgz
|
|
||||||
|
|
||||||
# Selenium Screenshots
|
# Selenium Screenshots
|
||||||
selenium_screenshots/
|
selenium_screenshots/
|
||||||
backups/
|
backups/
|
||||||
@ -204,3 +200,4 @@ media/
|
|||||||
*mmdb
|
*mmdb
|
||||||
|
|
||||||
.idea/
|
.idea/
|
||||||
|
/api/
|
||||||
|
128
CODE_OF_CONDUCT.md
Normal file
128
CODE_OF_CONDUCT.md
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
# Contributor Covenant Code of Conduct
|
||||||
|
|
||||||
|
## Our Pledge
|
||||||
|
|
||||||
|
We as members, contributors, and leaders pledge to make participation in our
|
||||||
|
community a harassment-free experience for everyone, regardless of age, body
|
||||||
|
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||||
|
identity and expression, level of experience, education, socio-economic status,
|
||||||
|
nationality, personal appearance, race, religion, or sexual identity
|
||||||
|
and orientation.
|
||||||
|
|
||||||
|
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||||
|
diverse, inclusive, and healthy community.
|
||||||
|
|
||||||
|
## Our Standards
|
||||||
|
|
||||||
|
Examples of behavior that contributes to a positive environment for our
|
||||||
|
community include:
|
||||||
|
|
||||||
|
* Demonstrating empathy and kindness toward other people
|
||||||
|
* Being respectful of differing opinions, viewpoints, and experiences
|
||||||
|
* Giving and gracefully accepting constructive feedback
|
||||||
|
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||||
|
and learning from the experience
|
||||||
|
* Focusing on what is best not just for us as individuals, but for the
|
||||||
|
overall community
|
||||||
|
|
||||||
|
Examples of unacceptable behavior include:
|
||||||
|
|
||||||
|
* The use of sexualized language or imagery, and sexual attention or
|
||||||
|
advances of any kind
|
||||||
|
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||||
|
* Public or private harassment
|
||||||
|
* Publishing others' private information, such as a physical or email
|
||||||
|
address, without their explicit permission
|
||||||
|
* Other conduct which could reasonably be considered inappropriate in a
|
||||||
|
professional setting
|
||||||
|
|
||||||
|
## Enforcement Responsibilities
|
||||||
|
|
||||||
|
Community leaders are responsible for clarifying and enforcing our standards of
|
||||||
|
acceptable behavior and will take appropriate and fair corrective action in
|
||||||
|
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||||
|
or harmful.
|
||||||
|
|
||||||
|
Community leaders have the right and responsibility to remove, edit, or reject
|
||||||
|
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||||
|
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||||
|
decisions when appropriate.
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
This Code of Conduct applies within all community spaces, and also applies when
|
||||||
|
an individual is officially representing the community in public spaces.
|
||||||
|
Examples of representing our community include using an official e-mail address,
|
||||||
|
posting via an official social media account, or acting as an appointed
|
||||||
|
representative at an online or offline event.
|
||||||
|
|
||||||
|
## Enforcement
|
||||||
|
|
||||||
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||||
|
reported to the community leaders responsible for enforcement at
|
||||||
|
hello@beryju.org.
|
||||||
|
All complaints will be reviewed and investigated promptly and fairly.
|
||||||
|
|
||||||
|
All community leaders are obligated to respect the privacy and security of the
|
||||||
|
reporter of any incident.
|
||||||
|
|
||||||
|
## Enforcement Guidelines
|
||||||
|
|
||||||
|
Community leaders will follow these Community Impact Guidelines in determining
|
||||||
|
the consequences for any action they deem in violation of this Code of Conduct:
|
||||||
|
|
||||||
|
### 1. Correction
|
||||||
|
|
||||||
|
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||||
|
unprofessional or unwelcome in the community.
|
||||||
|
|
||||||
|
**Consequence**: A private, written warning from community leaders, providing
|
||||||
|
clarity around the nature of the violation and an explanation of why the
|
||||||
|
behavior was inappropriate. A public apology may be requested.
|
||||||
|
|
||||||
|
### 2. Warning
|
||||||
|
|
||||||
|
**Community Impact**: A violation through a single incident or series
|
||||||
|
of actions.
|
||||||
|
|
||||||
|
**Consequence**: A warning with consequences for continued behavior. No
|
||||||
|
interaction with the people involved, including unsolicited interaction with
|
||||||
|
those enforcing the Code of Conduct, for a specified period of time. This
|
||||||
|
includes avoiding interactions in community spaces as well as external channels
|
||||||
|
like social media. Violating these terms may lead to a temporary or
|
||||||
|
permanent ban.
|
||||||
|
|
||||||
|
### 3. Temporary Ban
|
||||||
|
|
||||||
|
**Community Impact**: A serious violation of community standards, including
|
||||||
|
sustained inappropriate behavior.
|
||||||
|
|
||||||
|
**Consequence**: A temporary ban from any sort of interaction or public
|
||||||
|
communication with the community for a specified period of time. No public or
|
||||||
|
private interaction with the people involved, including unsolicited interaction
|
||||||
|
with those enforcing the Code of Conduct, is allowed during this period.
|
||||||
|
Violating these terms may lead to a permanent ban.
|
||||||
|
|
||||||
|
### 4. Permanent Ban
|
||||||
|
|
||||||
|
**Community Impact**: Demonstrating a pattern of violation of community
|
||||||
|
standards, including sustained inappropriate behavior, harassment of an
|
||||||
|
individual, or aggression toward or disparagement of classes of individuals.
|
||||||
|
|
||||||
|
**Consequence**: A permanent ban from any sort of public interaction within
|
||||||
|
the community.
|
||||||
|
|
||||||
|
## Attribution
|
||||||
|
|
||||||
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||||
|
version 2.0, available at
|
||||||
|
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
||||||
|
|
||||||
|
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
||||||
|
enforcement ladder](https://github.com/mozilla/diversity).
|
||||||
|
|
||||||
|
[homepage]: https://www.contributor-covenant.org
|
||||||
|
|
||||||
|
For answers to common questions about this code of conduct, see the FAQ at
|
||||||
|
https://www.contributor-covenant.org/faq. Translations are available at
|
||||||
|
https://www.contributor-covenant.org/translations.
|
180
CONTRIBUTING.md
Normal file
180
CONTRIBUTING.md
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
# Contributing to authentik
|
||||||
|
|
||||||
|
:+1::tada: Thanks for taking the time to contribute! :tada::+1:
|
||||||
|
|
||||||
|
The following is a set of guidelines for contributing to authentik and its components, which are hosted in the [goauthentik Organization](https://github.com/goauthentik) on GitHub. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.
|
||||||
|
|
||||||
|
#### Table Of Contents
|
||||||
|
|
||||||
|
[Code of Conduct](#code-of-conduct)
|
||||||
|
|
||||||
|
[I don't want to read this whole thing, I just have a question!!!](#i-dont-want-to-read-this-whole-thing-i-just-have-a-question)
|
||||||
|
|
||||||
|
[What should I know before I get started?](#what-should-i-know-before-i-get-started)
|
||||||
|
* [Atom and Packages](#atom-and-packages)
|
||||||
|
* [Atom Design Decisions](#design-decisions)
|
||||||
|
|
||||||
|
[How Can I Contribute?](#how-can-i-contribute)
|
||||||
|
* [Reporting Bugs](#reporting-bugs)
|
||||||
|
* [Suggesting Enhancements](#suggesting-enhancements)
|
||||||
|
* [Your First Code Contribution](#your-first-code-contribution)
|
||||||
|
* [Pull Requests](#pull-requests)
|
||||||
|
|
||||||
|
[Styleguides](#styleguides)
|
||||||
|
* [Git Commit Messages](#git-commit-messages)
|
||||||
|
* [JavaScript Styleguide](#javascript-styleguide)
|
||||||
|
* [CoffeeScript Styleguide](#coffeescript-styleguide)
|
||||||
|
* [Specs Styleguide](#specs-styleguide)
|
||||||
|
* [Documentation Styleguide](#documentation-styleguide)
|
||||||
|
|
||||||
|
[Additional Notes](#additional-notes)
|
||||||
|
* [Issue and Pull Request Labels](#issue-and-pull-request-labels)
|
||||||
|
|
||||||
|
## Code of Conduct
|
||||||
|
|
||||||
|
Basically, don't be a dickhead. This is an open-source non-profit project, that is made in the free time of Volunteers. If there's something you dislike or think can be done better, tell us! We'd love to hear any suggestions for improvement.
|
||||||
|
|
||||||
|
## I don't want to read this whole thing I just have a question!!!
|
||||||
|
|
||||||
|
Either [create a question on GitHub](https://github.com/goauthentik/authentik/issues/new?assignees=&labels=question&template=question.md&title=) or join [the Discord server](https://discord.gg/jg33eMhnj6)
|
||||||
|
|
||||||
|
## What should I know before I get started?
|
||||||
|
|
||||||
|
### The components
|
||||||
|
|
||||||
|
authentik consists of a few larger components:
|
||||||
|
|
||||||
|
- *authentik* the actual application server, is described below.
|
||||||
|
- *outpost-proxy* is a Go application based on a forked version of oauth2_proxy, which does identity-aware reverse proxying.
|
||||||
|
- *outpost-ldap* is a Go LDAP server that uses the *authentik* application server as its backend
|
||||||
|
- *web* is the web frontend, both for administrating and using authentik. It is written in TypeScript using lit-html and the PatternFly CSS Library.
|
||||||
|
- *website* is the Website/documentation, which uses docusaurus.
|
||||||
|
|
||||||
|
### authentik's structure
|
||||||
|
|
||||||
|
authentik is at it's very core a Django project. It consists of many individual django applications. These applications are intended to separate concerns, and they may share code between each other.
|
||||||
|
|
||||||
|
These are the current packages:
|
||||||
|
<a id="authentik-packages"/>
|
||||||
|
|
||||||
|
```
|
||||||
|
authentik
|
||||||
|
├── admin - Administrative tasks and APIs, no models (Version updates, Metrics, system tasks)
|
||||||
|
├── api - General API Configuration (Routes, Schema and general API utilities)
|
||||||
|
├── core - Core authentik functionality, central routes, core Models
|
||||||
|
├── crypto - Cryptography, currently used to generate and hold Certificates and Private Keys
|
||||||
|
├── events - Event Log, middleware and signals to generate signals
|
||||||
|
├── flows - Flows, the FlowPlanner and the FlowExecutor, used for all flows for authentication, authorization, etc
|
||||||
|
├── lib - Generic library of functions, few dependencies on other packages.
|
||||||
|
├── managed - Handle managed models and their state.
|
||||||
|
├── outposts - Configure and deploy outposts on kubernetes and docker.
|
||||||
|
├── policies - General PolicyEngine
|
||||||
|
│ ├── dummy - A Dummy policy used for testing
|
||||||
|
│ ├── event_matcher - Match events based on different criteria
|
||||||
|
│ ├── expiry - Check when a user's password was last set
|
||||||
|
│ ├── expression - Execute any arbitrary python code
|
||||||
|
│ ├── hibp - Check a password against HaveIBeenPwned
|
||||||
|
│ ├── password - Check a password against several rules
|
||||||
|
│ └── reputation - Check the user's/client's reputation
|
||||||
|
├── providers
|
||||||
|
│ ├── ldap - Provide LDAP access to authentik users/groups using an outpost
|
||||||
|
│ ├── oauth2 - OIDC-compliant OAuth2 provider
|
||||||
|
│ ├── proxy - Provides an identity-aware proxy using an outpost
|
||||||
|
│ └── saml - SAML2 Provider
|
||||||
|
├── recovery - Generate keys to use in case you lock yourself out
|
||||||
|
├── root - Root django application, contains global settings and routes
|
||||||
|
├── sources
|
||||||
|
│ ├── ldap - Sync LDAP users from OpenLDAP or Active Directory into authentik
|
||||||
|
│ ├── oauth - OAuth1 and OAuth2 Source
|
||||||
|
│ ├── plex - Plex source
|
||||||
|
│ └── saml - SAML2 Source
|
||||||
|
├── stages
|
||||||
|
│ ├── authenticator_duo - Configure a DUO authenticator
|
||||||
|
│ ├── authenticator_static - Configure TOTP backup keys
|
||||||
|
│ ├── authenticator_totp - Configure a TOTP authenticator
|
||||||
|
│ ├── authenticator_validate - Validate any authenticator
|
||||||
|
│ ├── authenticator_webauthn - Configure a WebAuthn authenticator
|
||||||
|
│ ├── captcha - Make the user pass a captcha
|
||||||
|
│ ├── consent - Let the user decide if they want to consent to an action
|
||||||
|
│ ├── deny - Static deny, can be used with policies
|
||||||
|
│ ├── dummy - Dummy stage to test
|
||||||
|
│ ├── email - Send the user an email and block execution until they click the link
|
||||||
|
│ ├── identification - Identify a user with any combination of fields
|
||||||
|
│ ├── invitation - Invitation system to limit flows to certain users
|
||||||
|
│ ├── password - Password authentication
|
||||||
|
│ ├── prompt - Arbitrary prompts
|
||||||
|
│ ├── user_delete - Delete the currently pending user
|
||||||
|
│ ├── user_login - Login the currently pending user
|
||||||
|
│ ├── user_logout - Logout the currently pending user
|
||||||
|
│ └── user_write - Write any currenetly pending data to the user.
|
||||||
|
└── tenants - Soft tennancy, configure defaults and branding per domain
|
||||||
|
```
|
||||||
|
|
||||||
|
This django project is running in gunicorn, which spawns multiple workers and threads. Gunicorn is run from a lightweight Go application which reverse-proxies it, handles static files and will eventually gain more functionality as more code is migrated to go.
|
||||||
|
|
||||||
|
There are also several background tasks which run in Celery, the root celery application is defined in `authentik.root.celery`.
|
||||||
|
|
||||||
|
## How Can I Contribute?
|
||||||
|
|
||||||
|
### Reporting Bugs
|
||||||
|
|
||||||
|
This section guides you through submitting a bug report for authentik. Following these guidelines helps maintainers and the community understand your report, reproduce the behavior, and find related reports.
|
||||||
|
|
||||||
|
Whenever authentik encounters an error, it will be logged as an Event with the type `system_exception`. This event type has a button to directly open a pre-filled GitHub issue form.
|
||||||
|
|
||||||
|
This form will have the full stack trace of the error that ocurred and shouldn't contain any sensitive data.
|
||||||
|
|
||||||
|
### Suggesting Enhancements
|
||||||
|
|
||||||
|
This section guides you through submitting an enhancement suggestion for authentik, including completely new features and minor improvements to existing functionality. Following these guidelines helps maintainers and the community understand your suggestion and find related suggestions.
|
||||||
|
|
||||||
|
When you are creating an enhancement suggestion, please fill in [the template](https://github.com/goauthentik/authentik/issues/new?assignees=&labels=enhancement&template=feature_request.md&title=), including the steps that you imagine you would take if the feature you're requesting existed.
|
||||||
|
|
||||||
|
### Your First Code Contribution
|
||||||
|
|
||||||
|
#### Local development
|
||||||
|
|
||||||
|
authentik can be run locally, all though depending on which part you want to work on, different pre-requisites are required.
|
||||||
|
|
||||||
|
This is documented in the [developer docs](https://goauthentik.io/developer-docs/)
|
||||||
|
|
||||||
|
### Pull Requests
|
||||||
|
|
||||||
|
The process described here has several goals:
|
||||||
|
|
||||||
|
- Maintain authentik's quality
|
||||||
|
- Fix problems that are important to users
|
||||||
|
- Engage the community in working toward the best possible authentik
|
||||||
|
- Enable a sustainable system for authentik's maintainers to review contributions
|
||||||
|
|
||||||
|
Please follow these steps to have your contribution considered by the maintainers:
|
||||||
|
|
||||||
|
1. Follow the [styleguides](#styleguides)
|
||||||
|
2. After you submit your pull request, verify that all [status checks](https://help.github.com/articles/about-status-checks/) are passing <details><summary>What if the status checks are failing?</summary>If a status check is failing, and you believe that the failure is unrelated to your change, please leave a comment on the pull request explaining why you believe the failure is unrelated. A maintainer will re-run the status check for you. If we conclude that the failure was a false positive, then we will open an issue to track that problem with our status check suite.</details>
|
||||||
|
3. Ensure your Code has tests. While it is not always possible to test every single case, the majority of the code should be tested.
|
||||||
|
|
||||||
|
While the prerequisites above must be satisfied prior to having your pull request reviewed, the reviewer(s) may ask you to complete additional design work, tests, or other changes before your pull request can be ultimately accepted.
|
||||||
|
|
||||||
|
## Styleguides
|
||||||
|
|
||||||
|
### Git Commit Messages
|
||||||
|
|
||||||
|
* Use the format of `<package>: <verb> <description>`
|
||||||
|
- See [here](#authentik-packages) for `package`
|
||||||
|
- Example: `providers/saml2: fix parsing of requests`
|
||||||
|
* Reference issues and pull requests liberally after the first line
|
||||||
|
|
||||||
|
### Python Styleguide
|
||||||
|
|
||||||
|
All Python code is linted with [black](https://black.readthedocs.io/en/stable/), [PyLint](https://www.pylint.org/) and [isort](https://pycqa.github.io/isort/).
|
||||||
|
|
||||||
|
authentik runs on Python 3.9 at the time of writing this.
|
||||||
|
|
||||||
|
* Use native type-annotations wherever possible.
|
||||||
|
* Add meaningful docstrings when possible.
|
||||||
|
* Ensure any database migrations work properly from the last stable version (this is checked via CI)
|
||||||
|
* If your code changes central functions, make sure nothing else is broken.
|
||||||
|
|
||||||
|
### Documentation Styleguide
|
||||||
|
|
||||||
|
* Use [MDX](https://mdxjs.com/) whenever appropriate.
|
64
Dockerfile
64
Dockerfile
@ -8,36 +8,73 @@ WORKDIR /app/
|
|||||||
|
|
||||||
RUN pip install pipenv && \
|
RUN pip install pipenv && \
|
||||||
pipenv lock -r > requirements.txt && \
|
pipenv lock -r > requirements.txt && \
|
||||||
pipenv lock -rd > requirements-dev.txt
|
pipenv lock -r --dev-only > requirements-dev.txt
|
||||||
|
|
||||||
# Stage 2: Build webui
|
# Stage 2: Build website
|
||||||
FROM node as npm-builder
|
FROM node as website-builder
|
||||||
|
|
||||||
COPY ./web /static/
|
COPY ./website /static/
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
RUN cd /static && npm i --production=false && npm run build
|
RUN cd /static && npm i && npm run build-docs-only
|
||||||
|
|
||||||
# Stage 3: Build go proxy
|
# Stage 3: Build web API
|
||||||
FROM golang:1.16.4 AS builder
|
FROM openapitools/openapi-generator-cli as web-api-builder
|
||||||
|
|
||||||
|
COPY ./schema.yml /local/schema.yml
|
||||||
|
|
||||||
|
RUN docker-entrypoint.sh generate \
|
||||||
|
-i /local/schema.yml \
|
||||||
|
-g typescript-fetch \
|
||||||
|
-o /local/web/api \
|
||||||
|
--additional-properties=typescriptThreePlus=true,supportsES6=true,npmName=authentik-api,npmVersion=1.0.0
|
||||||
|
|
||||||
|
# Stage 3: Generate API Client
|
||||||
|
FROM openapitools/openapi-generator-cli as go-api-builder
|
||||||
|
|
||||||
|
COPY ./schema.yml /local/schema.yml
|
||||||
|
|
||||||
|
RUN docker-entrypoint.sh generate \
|
||||||
|
--git-host goauthentik.io \
|
||||||
|
--git-repo-id outpost \
|
||||||
|
--git-user-id api \
|
||||||
|
-i /local/schema.yml \
|
||||||
|
-g go \
|
||||||
|
-o /local/api \
|
||||||
|
--additional-properties=packageName=api,enumClassPrefix=true,useOneOfDiscriminatorLookup=true && \
|
||||||
|
rm -f /local/api/go.mod /local/api/go.sum
|
||||||
|
|
||||||
|
# Stage 4: Build webui
|
||||||
|
FROM node as web-builder
|
||||||
|
|
||||||
|
COPY ./web /static/
|
||||||
|
COPY --from=web-api-builder /local/web/api /static/api
|
||||||
|
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
RUN cd /static && npm i && npm run build
|
||||||
|
|
||||||
|
# Stage 5: Build go proxy
|
||||||
|
FROM golang:1.16.6 AS builder
|
||||||
|
|
||||||
WORKDIR /work
|
WORKDIR /work
|
||||||
|
|
||||||
COPY --from=npm-builder /static/robots.txt /work/web/robots.txt
|
COPY --from=web-builder /static/robots.txt /work/web/robots.txt
|
||||||
COPY --from=npm-builder /static/security.txt /work/web/security.txt
|
COPY --from=web-builder /static/security.txt /work/web/security.txt
|
||||||
COPY --from=npm-builder /static/dist/ /work/web/dist/
|
COPY --from=web-builder /static/dist/ /work/web/dist/
|
||||||
COPY --from=npm-builder /static/authentik/ /work/web/authentik/
|
COPY --from=web-builder /static/authentik/ /work/web/authentik/
|
||||||
|
COPY --from=website-builder /static/help/ /work/website/help/
|
||||||
|
|
||||||
# RUN ls /work/web/static/authentik/ && exit 1
|
COPY --from=go-api-builder /local/api api
|
||||||
COPY ./cmd /work/cmd
|
COPY ./cmd /work/cmd
|
||||||
COPY ./web/static.go /work/web/static.go
|
COPY ./web/static.go /work/web/static.go
|
||||||
|
COPY ./website/static.go /work/website/static.go
|
||||||
COPY ./internal /work/internal
|
COPY ./internal /work/internal
|
||||||
COPY ./go.mod /work/go.mod
|
COPY ./go.mod /work/go.mod
|
||||||
COPY ./go.sum /work/go.sum
|
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 4: Run
|
# Stage 6: Run
|
||||||
FROM python:3.9-slim-buster
|
FROM python:3.9-slim-buster
|
||||||
|
|
||||||
WORKDIR /
|
WORKDIR /
|
||||||
@ -65,6 +102,7 @@ RUN apt-get update && \
|
|||||||
COPY ./authentik/ /authentik
|
COPY ./authentik/ /authentik
|
||||||
COPY ./pyproject.toml /
|
COPY ./pyproject.toml /
|
||||||
COPY ./xml /xml
|
COPY ./xml /xml
|
||||||
|
COPY ./tests /tests
|
||||||
COPY ./manage.py /
|
COPY ./manage.py /
|
||||||
COPY ./lifecycle/ /lifecycle
|
COPY ./lifecycle/ /lifecycle
|
||||||
COPY --from=builder /work/authentik /authentik-proxy
|
COPY --from=builder /work/authentik /authentik-proxy
|
||||||
|
34
Makefile
34
Makefile
@ -1,5 +1,7 @@
|
|||||||
.SHELLFLAGS += -x -e
|
.SHELLFLAGS += -x -e
|
||||||
PWD = $(shell pwd)
|
PWD = $(shell pwd)
|
||||||
|
UID = $(shell id -u)
|
||||||
|
GID = $(shell id -g)
|
||||||
|
|
||||||
all: lint-fix lint test gen
|
all: lint-fix lint test gen
|
||||||
|
|
||||||
@ -25,16 +27,42 @@ lint:
|
|||||||
bandit -r authentik tests lifecycle -x node_modules
|
bandit -r authentik tests lifecycle -x node_modules
|
||||||
pylint authentik tests lifecycle
|
pylint authentik tests lifecycle
|
||||||
|
|
||||||
gen:
|
gen-build:
|
||||||
./manage.py generate_swagger -o swagger.yaml -f yaml
|
./manage.py spectacular --file schema.yml
|
||||||
|
|
||||||
|
gen-clean:
|
||||||
|
rm -rf web/api/src/
|
||||||
|
rm -rf api/
|
||||||
|
|
||||||
|
gen-web:
|
||||||
docker run \
|
docker run \
|
||||||
--rm -v ${PWD}:/local \
|
--rm -v ${PWD}:/local \
|
||||||
|
--user ${UID}:${GID} \
|
||||||
openapitools/openapi-generator-cli generate \
|
openapitools/openapi-generator-cli generate \
|
||||||
-i /local/swagger.yaml \
|
-i /local/schema.yml \
|
||||||
-g typescript-fetch \
|
-g typescript-fetch \
|
||||||
-o /local/web/api \
|
-o /local/web/api \
|
||||||
--additional-properties=typescriptThreePlus=true,supportsES6=true,npmName=authentik-api,npmVersion=1.0.0
|
--additional-properties=typescriptThreePlus=true,supportsES6=true,npmName=authentik-api,npmVersion=1.0.0
|
||||||
cd web/api && npx tsc
|
cd web/api && npx tsc
|
||||||
|
|
||||||
|
gen-outpost:
|
||||||
|
docker run \
|
||||||
|
--rm -v ${PWD}:/local \
|
||||||
|
--user ${UID}:${GID} \
|
||||||
|
openapitools/openapi-generator-cli generate \
|
||||||
|
--git-host goauthentik.io \
|
||||||
|
--git-repo-id outpost \
|
||||||
|
--git-user-id api \
|
||||||
|
-i /local/schema.yml \
|
||||||
|
-g go \
|
||||||
|
-o /local/api \
|
||||||
|
--additional-properties=packageName=api,enumClassPrefix=true,useOneOfDiscriminatorLookup=true
|
||||||
|
rm -f api/go.mod api/go.sum
|
||||||
|
|
||||||
|
gen: gen-build gen-clean gen-web gen-outpost
|
||||||
|
|
||||||
|
migrate:
|
||||||
|
python -m lifecycle.migrate
|
||||||
|
|
||||||
run:
|
run:
|
||||||
go run -v cmd/server/main.go
|
go run -v cmd/server/main.go
|
||||||
|
6
Pipfile
6
Pipfile
@ -22,7 +22,7 @@ django-storages = "*"
|
|||||||
djangorestframework = "*"
|
djangorestframework = "*"
|
||||||
djangorestframework-guardian = "*"
|
djangorestframework-guardian = "*"
|
||||||
docker = "*"
|
docker = "*"
|
||||||
drf_yasg = "*"
|
drf-spectacular = "*"
|
||||||
facebook-sdk = "*"
|
facebook-sdk = "*"
|
||||||
geoip2 = "*"
|
geoip2 = "*"
|
||||||
gunicorn = "*"
|
gunicorn = "*"
|
||||||
@ -44,6 +44,10 @@ urllib3 = {extras = ["secure"],version = "*"}
|
|||||||
uvicorn = {extras = ["standard"],version = "*"}
|
uvicorn = {extras = ["standard"],version = "*"}
|
||||||
webauthn = "*"
|
webauthn = "*"
|
||||||
xmlsec = "*"
|
xmlsec = "*"
|
||||||
|
duo-client = "*"
|
||||||
|
ua-parser = "*"
|
||||||
|
deepmerge = "*"
|
||||||
|
colorama = "*"
|
||||||
|
|
||||||
[requires]
|
[requires]
|
||||||
python_version = "3.9"
|
python_version = "3.9"
|
||||||
|
885
Pipfile.lock
generated
885
Pipfile.lock
generated
File diff suppressed because it is too large
Load Diff
@ -21,7 +21,7 @@ authentik is an open-source Identity Provider focused on flexibility and versati
|
|||||||
|
|
||||||
For small/test setups it is recommended to use docker-compose, see the [documentation](https://goauthentik.io/docs/installation/docker-compose/)
|
For small/test setups it is recommended to use docker-compose, see the [documentation](https://goauthentik.io/docs/installation/docker-compose/)
|
||||||
|
|
||||||
For bigger setups, there is a Helm Chart in the `helm/` directory. This is documented [here](https://goauthentik.io/docs/installation/kubernetes/)
|
For bigger setups, there is a Helm Chart [here])(https://github.com/goauthentik/helm). This is documented [here](https://goauthentik.io/docs/installation/kubernetes/)
|
||||||
|
|
||||||
## Screenshots
|
## Screenshots
|
||||||
|
|
||||||
|
@ -2,10 +2,13 @@
|
|||||||
|
|
||||||
## Supported Versions
|
## Supported Versions
|
||||||
|
|
||||||
|
(.x being the latest patch release for each version)
|
||||||
|
|
||||||
| Version | Supported |
|
| Version | Supported |
|
||||||
| ---------- | ------------------ |
|
| ---------- | ------------------ |
|
||||||
| 2021.4.x | :white_check_mark: |
|
|
||||||
| 2021.5.x | :white_check_mark: |
|
| 2021.5.x | :white_check_mark: |
|
||||||
|
| 2021.6.x | :white_check_mark: |
|
||||||
|
| 2021.7.x | :white_check_mark: |
|
||||||
|
|
||||||
## Reporting a Vulnerability
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
"""authentik"""
|
"""authentik"""
|
||||||
__version__ = "2021.5.1"
|
__version__ = "2021.7.3"
|
||||||
ENV_GIT_HASH_KEY = "GIT_BUILD_HASH"
|
ENV_GIT_HASH_KEY = "GIT_BUILD_HASH"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
"""Meta API"""
|
"""Meta API"""
|
||||||
from drf_yasg.utils import swagger_auto_schema
|
from drf_spectacular.utils import extend_schema
|
||||||
from rest_framework.fields import CharField
|
from rest_framework.fields import CharField
|
||||||
from rest_framework.permissions import IsAdminUser
|
from rest_framework.permissions import IsAdminUser
|
||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
@ -22,7 +22,7 @@ class AppsViewSet(ViewSet):
|
|||||||
|
|
||||||
permission_classes = [IsAdminUser]
|
permission_classes = [IsAdminUser]
|
||||||
|
|
||||||
@swagger_auto_schema(responses={200: AppSerializer(many=True)})
|
@extend_schema(responses={200: AppSerializer(many=True)})
|
||||||
def list(self, request: Request) -> Response:
|
def list(self, request: Request) -> Response:
|
||||||
"""List current messages and pass into Serializer"""
|
"""List current messages and pass into Serializer"""
|
||||||
data = []
|
data = []
|
||||||
|
@ -7,12 +7,12 @@ from django.db.models import Count, ExpressionWrapper, F
|
|||||||
from django.db.models.fields import DurationField
|
from django.db.models.fields import DurationField
|
||||||
from django.db.models.functions import ExtractHour
|
from django.db.models.functions import ExtractHour
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
from drf_yasg.utils import swagger_auto_schema, swagger_serializer_method
|
from drf_spectacular.utils import extend_schema, extend_schema_field
|
||||||
from rest_framework.fields import IntegerField, SerializerMethodField
|
from rest_framework.fields import IntegerField, SerializerMethodField
|
||||||
from rest_framework.permissions import IsAdminUser
|
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.views import APIView
|
||||||
|
|
||||||
from authentik.core.api.utils import PassiveSerializer
|
from authentik.core.api.utils import PassiveSerializer
|
||||||
from authentik.events.models import Event, EventAction
|
from authentik.events.models import Event, EventAction
|
||||||
@ -58,24 +58,24 @@ class LoginMetricsSerializer(PassiveSerializer):
|
|||||||
logins_per_1h = SerializerMethodField()
|
logins_per_1h = SerializerMethodField()
|
||||||
logins_failed_per_1h = SerializerMethodField()
|
logins_failed_per_1h = SerializerMethodField()
|
||||||
|
|
||||||
@swagger_serializer_method(serializer_or_field=CoordinateSerializer(many=True))
|
@extend_schema_field(CoordinateSerializer(many=True))
|
||||||
def get_logins_per_1h(self, _):
|
def get_logins_per_1h(self, _):
|
||||||
"""Get successful logins per hour for the last 24 hours"""
|
"""Get successful logins per hour for the last 24 hours"""
|
||||||
return get_events_per_1h(action=EventAction.LOGIN)
|
return get_events_per_1h(action=EventAction.LOGIN)
|
||||||
|
|
||||||
@swagger_serializer_method(serializer_or_field=CoordinateSerializer(many=True))
|
@extend_schema_field(CoordinateSerializer(many=True))
|
||||||
def get_logins_failed_per_1h(self, _):
|
def get_logins_failed_per_1h(self, _):
|
||||||
"""Get failed logins per hour for the last 24 hours"""
|
"""Get failed logins per hour for the last 24 hours"""
|
||||||
return get_events_per_1h(action=EventAction.LOGIN_FAILED)
|
return get_events_per_1h(action=EventAction.LOGIN_FAILED)
|
||||||
|
|
||||||
|
|
||||||
class AdministrationMetricsViewSet(ViewSet):
|
class AdministrationMetricsViewSet(APIView):
|
||||||
"""Login Metrics per 1h"""
|
"""Login Metrics per 1h"""
|
||||||
|
|
||||||
permission_classes = [IsAdminUser]
|
permission_classes = [IsAdminUser]
|
||||||
|
|
||||||
@swagger_auto_schema(responses={200: LoginMetricsSerializer(many=False)})
|
@extend_schema(responses={200: LoginMetricsSerializer(many=False)})
|
||||||
def list(self, request: Request) -> Response:
|
def get(self, request: Request) -> Response:
|
||||||
"""Login Metrics per 1h"""
|
"""Login Metrics per 1h"""
|
||||||
serializer = LoginMetricsSerializer(True)
|
serializer = LoginMetricsSerializer(True)
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
91
authentik/admin/api/system.py
Normal file
91
authentik/admin/api/system.py
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
"""authentik administration overview"""
|
||||||
|
import os
|
||||||
|
import platform
|
||||||
|
from datetime import datetime
|
||||||
|
from sys import version as python_version
|
||||||
|
from typing import TypedDict
|
||||||
|
|
||||||
|
from django.utils.timezone import now
|
||||||
|
from drf_spectacular.utils import extend_schema
|
||||||
|
from gunicorn import version_info as gunicorn_version
|
||||||
|
from kubernetes.config.incluster_config import SERVICE_HOST_ENV_NAME
|
||||||
|
from rest_framework.fields import SerializerMethodField
|
||||||
|
from rest_framework.permissions import IsAdminUser
|
||||||
|
from rest_framework.request import Request
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
|
from authentik.core.api.utils import PassiveSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class RuntimeDict(TypedDict):
|
||||||
|
"""Runtime information"""
|
||||||
|
|
||||||
|
python_version: str
|
||||||
|
gunicorn_version: str
|
||||||
|
environment: str
|
||||||
|
architecture: str
|
||||||
|
platform: str
|
||||||
|
uname: str
|
||||||
|
|
||||||
|
|
||||||
|
class SystemSerializer(PassiveSerializer):
|
||||||
|
"""Get system information."""
|
||||||
|
|
||||||
|
http_headers = SerializerMethodField()
|
||||||
|
http_host = SerializerMethodField()
|
||||||
|
http_is_secure = SerializerMethodField()
|
||||||
|
runtime = SerializerMethodField()
|
||||||
|
tenant = SerializerMethodField()
|
||||||
|
server_time = SerializerMethodField()
|
||||||
|
|
||||||
|
def get_http_headers(self, request: Request) -> dict[str, str]:
|
||||||
|
"""Get HTTP Request headers"""
|
||||||
|
headers = {}
|
||||||
|
for key, value in request.META.items():
|
||||||
|
if not isinstance(value, str):
|
||||||
|
continue
|
||||||
|
headers[key] = value
|
||||||
|
return headers
|
||||||
|
|
||||||
|
def get_http_host(self, request: Request) -> str:
|
||||||
|
"""Get HTTP host"""
|
||||||
|
return request._request.get_host()
|
||||||
|
|
||||||
|
def get_http_is_secure(self, request: Request) -> bool:
|
||||||
|
"""Get HTTP Secure flag"""
|
||||||
|
return request._request.is_secure()
|
||||||
|
|
||||||
|
def get_runtime(self, request: Request) -> RuntimeDict:
|
||||||
|
"""Get versions"""
|
||||||
|
return {
|
||||||
|
"python_version": python_version,
|
||||||
|
"gunicorn_version": ".".join(str(x) for x in gunicorn_version),
|
||||||
|
"environment": "kubernetes"
|
||||||
|
if SERVICE_HOST_ENV_NAME in os.environ
|
||||||
|
else "compose",
|
||||||
|
"architecture": platform.machine(),
|
||||||
|
"platform": platform.platform(),
|
||||||
|
"uname": " ".join(platform.uname()),
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_tenant(self, request: Request) -> str:
|
||||||
|
"""Currently active tenant"""
|
||||||
|
return str(request._request.tenant)
|
||||||
|
|
||||||
|
def get_server_time(self, request: Request) -> datetime:
|
||||||
|
"""Current server time"""
|
||||||
|
return now()
|
||||||
|
|
||||||
|
|
||||||
|
class SystemView(APIView):
|
||||||
|
"""Get system information."""
|
||||||
|
|
||||||
|
permission_classes = [IsAdminUser]
|
||||||
|
pagination_class = None
|
||||||
|
filter_backends = []
|
||||||
|
|
||||||
|
@extend_schema(responses={200: SystemSerializer(many=False)})
|
||||||
|
def get(self, request: Request) -> Response:
|
||||||
|
"""Get system information."""
|
||||||
|
return Response(SystemSerializer(request).data)
|
@ -4,7 +4,8 @@ from importlib import import_module
|
|||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.http.response import Http404
|
from django.http.response import Http404
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from drf_yasg.utils import swagger_auto_schema
|
from drf_spectacular.types import OpenApiTypes
|
||||||
|
from drf_spectacular.utils import OpenApiResponse, extend_schema
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.fields import CharField, ChoiceField, DateTimeField, ListField
|
from rest_framework.fields import CharField, ChoiceField, DateTimeField, ListField
|
||||||
from rest_framework.permissions import IsAdminUser
|
from rest_framework.permissions import IsAdminUser
|
||||||
@ -21,7 +22,7 @@ class TaskSerializer(PassiveSerializer):
|
|||||||
|
|
||||||
task_name = CharField()
|
task_name = CharField()
|
||||||
task_description = CharField()
|
task_description = CharField()
|
||||||
task_finish_timestamp = DateTimeField(source="finish_timestamp")
|
task_finish_timestamp = DateTimeField(source="finish_time")
|
||||||
|
|
||||||
status = ChoiceField(
|
status = ChoiceField(
|
||||||
source="result.status.name",
|
source="result.status.name",
|
||||||
@ -29,14 +30,32 @@ class TaskSerializer(PassiveSerializer):
|
|||||||
)
|
)
|
||||||
messages = ListField(source="result.messages")
|
messages = ListField(source="result.messages")
|
||||||
|
|
||||||
|
def to_representation(self, instance):
|
||||||
|
"""When a new version of authentik adds fields to TaskInfo,
|
||||||
|
the API will fail with an AttributeError, as the classes
|
||||||
|
are pickled in cache. In that case, just delete the info"""
|
||||||
|
try:
|
||||||
|
return super().to_representation(instance)
|
||||||
|
except AttributeError:
|
||||||
|
if isinstance(self.instance, list):
|
||||||
|
for inst in self.instance:
|
||||||
|
inst.delete()
|
||||||
|
else:
|
||||||
|
self.instance.delete()
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
class TaskViewSet(ViewSet):
|
class TaskViewSet(ViewSet):
|
||||||
"""Read-only view set that returns all background tasks"""
|
"""Read-only view set that returns all background tasks"""
|
||||||
|
|
||||||
permission_classes = [IsAdminUser]
|
permission_classes = [IsAdminUser]
|
||||||
|
serializer_class = TaskSerializer
|
||||||
|
|
||||||
@swagger_auto_schema(
|
@extend_schema(
|
||||||
responses={200: TaskSerializer(many=False), 404: "Task not found"}
|
responses={
|
||||||
|
200: TaskSerializer(many=False),
|
||||||
|
404: OpenApiResponse(description="Task not found"),
|
||||||
|
}
|
||||||
)
|
)
|
||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
def retrieve(self, request: Request, pk=None) -> Response:
|
def retrieve(self, request: Request, pk=None) -> Response:
|
||||||
@ -46,18 +65,19 @@ class TaskViewSet(ViewSet):
|
|||||||
raise Http404
|
raise Http404
|
||||||
return Response(TaskSerializer(task, many=False).data)
|
return Response(TaskSerializer(task, many=False).data)
|
||||||
|
|
||||||
@swagger_auto_schema(responses={200: TaskSerializer(many=True)})
|
@extend_schema(responses={200: TaskSerializer(many=True)})
|
||||||
def list(self, request: Request) -> Response:
|
def list(self, request: Request) -> Response:
|
||||||
"""List system tasks"""
|
"""List system tasks"""
|
||||||
tasks = sorted(TaskInfo.all().values(), key=lambda task: task.task_name)
|
tasks = sorted(TaskInfo.all().values(), key=lambda task: task.task_name)
|
||||||
return Response(TaskSerializer(tasks, many=True).data)
|
return Response(TaskSerializer(tasks, many=True).data)
|
||||||
|
|
||||||
@swagger_auto_schema(
|
@extend_schema(
|
||||||
|
request=OpenApiTypes.NONE,
|
||||||
responses={
|
responses={
|
||||||
204: "Task retried successfully",
|
204: OpenApiResponse(description="Task retried successfully"),
|
||||||
404: "Task not found",
|
404: OpenApiResponse(description="Task not found"),
|
||||||
500: "Failed to retry task",
|
500: OpenApiResponse(description="Failed to retry task"),
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
@action(detail=True, methods=["post"])
|
@action(detail=True, methods=["post"])
|
||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
from os import environ
|
from os import environ
|
||||||
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from drf_yasg.utils import swagger_auto_schema
|
from drf_spectacular.utils import extend_schema
|
||||||
from packaging.version import parse
|
from packaging.version import parse
|
||||||
from rest_framework.fields import SerializerMethodField
|
from rest_framework.fields import SerializerMethodField
|
||||||
from rest_framework.mixins import ListModelMixin
|
|
||||||
from rest_framework.permissions import IsAuthenticated
|
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.viewsets import GenericViewSet
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
from authentik import ENV_GIT_HASH_KEY, __version__
|
from authentik import ENV_GIT_HASH_KEY, __version__
|
||||||
from authentik.admin.tasks import VERSION_CACHE_KEY, update_latest_version
|
from authentik.admin.tasks import VERSION_CACHE_KEY, update_latest_version
|
||||||
@ -47,17 +46,14 @@ class VersionSerializer(PassiveSerializer):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class VersionViewSet(ListModelMixin, GenericViewSet):
|
class VersionView(APIView):
|
||||||
"""Get running and latest version."""
|
"""Get running and latest version."""
|
||||||
|
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
pagination_class = None
|
pagination_class = None
|
||||||
filter_backends = []
|
filter_backends = []
|
||||||
|
|
||||||
def get_queryset(self): # pragma: no cover
|
@extend_schema(responses={200: VersionSerializer(many=False)})
|
||||||
return None
|
def get(self, request: Request) -> Response:
|
||||||
|
|
||||||
@swagger_auto_schema(responses={200: VersionSerializer(many=False)})
|
|
||||||
def list(self, request: Request) -> Response:
|
|
||||||
"""Get running and latest version."""
|
"""Get running and latest version."""
|
||||||
return Response(VersionSerializer(True).data)
|
return Response(VersionSerializer(True).data)
|
||||||
|
@ -1,25 +1,26 @@
|
|||||||
"""authentik administration overview"""
|
"""authentik administration overview"""
|
||||||
from rest_framework.mixins import ListModelMixin
|
from drf_spectacular.utils import extend_schema, inline_serializer
|
||||||
|
from prometheus_client import Gauge
|
||||||
|
from rest_framework.fields import IntegerField
|
||||||
from rest_framework.permissions import IsAdminUser
|
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.serializers import Serializer
|
from rest_framework.views import APIView
|
||||||
from rest_framework.viewsets import GenericViewSet
|
|
||||||
|
|
||||||
from authentik.root.celery import CELERY_APP
|
from authentik.root.celery import CELERY_APP
|
||||||
|
|
||||||
|
GAUGE_WORKERS = Gauge("authentik_admin_workers", "Currently connected workers")
|
||||||
|
|
||||||
class WorkerViewSet(ListModelMixin, GenericViewSet):
|
|
||||||
|
class WorkerView(APIView):
|
||||||
"""Get currently connected worker count."""
|
"""Get currently connected worker count."""
|
||||||
|
|
||||||
serializer_class = Serializer
|
|
||||||
permission_classes = [IsAdminUser]
|
permission_classes = [IsAdminUser]
|
||||||
|
|
||||||
def get_queryset(self): # pragma: no cover
|
@extend_schema(
|
||||||
return None
|
responses=inline_serializer("Workers", fields={"count": IntegerField()})
|
||||||
|
|
||||||
def list(self, request: Request) -> Response:
|
|
||||||
"""Get currently connected worker count."""
|
|
||||||
return Response(
|
|
||||||
{"pagination": {"count": len(CELERY_APP.control.ping(timeout=0.5))}}
|
|
||||||
)
|
)
|
||||||
|
def get(self, request: Request) -> Response:
|
||||||
|
"""Get currently connected worker count."""
|
||||||
|
count = len(CELERY_APP.control.ping(timeout=0.5))
|
||||||
|
return Response({"count": count})
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
"""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
|
||||||
from packaging.version import parse
|
from packaging.version import parse
|
||||||
|
from prometheus_client import Info
|
||||||
from requests import RequestException, get
|
from requests import RequestException, get
|
||||||
from structlog.stdlib import get_logger
|
from structlog.stdlib import get_logger
|
||||||
|
|
||||||
from authentik import __version__
|
from authentik import ENV_GIT_HASH_KEY, __version__
|
||||||
from authentik.events.models import Event, EventAction
|
from authentik.events.models import Event, EventAction
|
||||||
from authentik.events.monitored_tasks import MonitoredTask, TaskResult, TaskResultStatus
|
from authentik.events.monitored_tasks import MonitoredTask, TaskResult, TaskResultStatus
|
||||||
from authentik.root.celery import CELERY_APP
|
from authentik.root.celery import CELERY_APP
|
||||||
@ -17,6 +19,18 @@ VERSION_CACHE_KEY = "authentik_latest_version"
|
|||||||
VERSION_CACHE_TIMEOUT = 8 * 60 * 60 # 8 hours
|
VERSION_CACHE_TIMEOUT = 8 * 60 * 60 # 8 hours
|
||||||
# Chop of the first ^ because we want to search the entire string
|
# Chop of the first ^ because we want to search the entire string
|
||||||
URL_FINDER = URLValidator.regex.pattern[1:]
|
URL_FINDER = URLValidator.regex.pattern[1:]
|
||||||
|
PROM_INFO = Info("authentik_version", "Currently running authentik version")
|
||||||
|
|
||||||
|
|
||||||
|
def _set_prom_info():
|
||||||
|
"""Set prometheus info for version"""
|
||||||
|
PROM_INFO.info(
|
||||||
|
{
|
||||||
|
"version": __version__,
|
||||||
|
"latest": cache.get(VERSION_CACHE_KEY, ""),
|
||||||
|
"build_hash": environ.get(ENV_GIT_HASH_KEY, ""),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@CELERY_APP.task(bind=True, base=MonitoredTask)
|
@CELERY_APP.task(bind=True, base=MonitoredTask)
|
||||||
@ -36,6 +50,7 @@ def update_latest_version(self: MonitoredTask):
|
|||||||
TaskResultStatus.SUCCESSFUL, ["Successfully updated latest Version"]
|
TaskResultStatus.SUCCESSFUL, ["Successfully updated latest Version"]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
_set_prom_info()
|
||||||
# Check if upstream version is newer than what we're running,
|
# Check if upstream version is newer than what we're running,
|
||||||
# and if no event exists yet, create one.
|
# and if no event exists yet, create one.
|
||||||
local_version = parse(__version__)
|
local_version = parse(__version__)
|
||||||
@ -53,3 +68,6 @@ def update_latest_version(self: MonitoredTask):
|
|||||||
except (RequestException, IndexError) as exc:
|
except (RequestException, IndexError) as exc:
|
||||||
cache.set(VERSION_CACHE_KEY, "0.0.0", VERSION_CACHE_TIMEOUT)
|
cache.set(VERSION_CACHE_KEY, "0.0.0", VERSION_CACHE_TIMEOUT)
|
||||||
self.set_status(TaskResult(TaskResultStatus.ERROR).with_error(exc))
|
self.set_status(TaskResult(TaskResultStatus.ERROR).with_error(exc))
|
||||||
|
|
||||||
|
|
||||||
|
_set_prom_info()
|
||||||
|
@ -74,24 +74,29 @@ class TestAdminAPI(TestCase):
|
|||||||
|
|
||||||
def test_version(self):
|
def test_version(self):
|
||||||
"""Test Version API"""
|
"""Test Version API"""
|
||||||
response = self.client.get(reverse("authentik_api:admin_version-list"))
|
response = self.client.get(reverse("authentik_api:admin_version"))
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
body = loads(response.content)
|
body = loads(response.content)
|
||||||
self.assertEqual(body["version_current"], __version__)
|
self.assertEqual(body["version_current"], __version__)
|
||||||
|
|
||||||
def test_workers(self):
|
def test_workers(self):
|
||||||
"""Test Workers API"""
|
"""Test Workers API"""
|
||||||
response = self.client.get(reverse("authentik_api:admin_workers-list"))
|
response = self.client.get(reverse("authentik_api:admin_workers"))
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
body = loads(response.content)
|
body = loads(response.content)
|
||||||
self.assertEqual(body["pagination"]["count"], 0)
|
self.assertEqual(body["count"], 0)
|
||||||
|
|
||||||
def test_metrics(self):
|
def test_metrics(self):
|
||||||
"""Test metrics API"""
|
"""Test metrics API"""
|
||||||
response = self.client.get(reverse("authentik_api:admin_metrics-list"))
|
response = self.client.get(reverse("authentik_api:admin_metrics"))
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
def test_apps(self):
|
def test_apps(self):
|
||||||
"""Test apps API"""
|
"""Test apps API"""
|
||||||
response = self.client.get(reverse("authentik_api:apps-list"))
|
response = self.client.get(reverse("authentik_api:apps-list"))
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_system(self):
|
||||||
|
"""Test system API"""
|
||||||
|
response = self.client.get(reverse("authentik_api:admin_system"))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
@ -10,3 +10,25 @@ class AuthentikAPIConfig(AppConfig):
|
|||||||
label = "authentik_api"
|
label = "authentik_api"
|
||||||
mountpoint = "api/"
|
mountpoint = "api/"
|
||||||
verbose_name = "authentik API"
|
verbose_name = "authentik API"
|
||||||
|
|
||||||
|
def ready(self) -> None:
|
||||||
|
from drf_spectacular.extensions import OpenApiAuthenticationExtension
|
||||||
|
|
||||||
|
from authentik.api.authentication import TokenAuthentication
|
||||||
|
|
||||||
|
# Class is defined here as it needs to be created early enough that drf-spectacular will
|
||||||
|
# find it, but also won't cause any import issues
|
||||||
|
# pylint: disable=unused-variable
|
||||||
|
class TokenSchema(OpenApiAuthenticationExtension):
|
||||||
|
"""Auth schema"""
|
||||||
|
|
||||||
|
target_class = TokenAuthentication
|
||||||
|
name = "authentik"
|
||||||
|
|
||||||
|
def get_security_definition(self, auto_schema):
|
||||||
|
"""Auth schema"""
|
||||||
|
return {
|
||||||
|
"type": "apiKey",
|
||||||
|
"in": "header",
|
||||||
|
"name": "Authorization",
|
||||||
|
}
|
||||||
|
@ -17,9 +17,9 @@ LOGGER = get_logger()
|
|||||||
def token_from_header(raw_header: bytes) -> Optional[Token]:
|
def token_from_header(raw_header: bytes) -> Optional[Token]:
|
||||||
"""raw_header in the Format of `Bearer dGVzdDp0ZXN0`"""
|
"""raw_header in the Format of `Bearer dGVzdDp0ZXN0`"""
|
||||||
auth_credentials = raw_header.decode()
|
auth_credentials = raw_header.decode()
|
||||||
if auth_credentials == "":
|
if auth_credentials == "" or " " not in auth_credentials:
|
||||||
return None
|
return None
|
||||||
auth_type, auth_credentials = auth_credentials.split()
|
auth_type, _, auth_credentials = auth_credentials.partition(" ")
|
||||||
if auth_type.lower() not in ["basic", "bearer"]:
|
if auth_type.lower() not in ["basic", "bearer"]:
|
||||||
LOGGER.debug("Unsupported authentication type, denying", type=auth_type.lower())
|
LOGGER.debug("Unsupported authentication type, denying", type=auth_type.lower())
|
||||||
raise AuthenticationFailed("Unsupported authentication type")
|
raise AuthenticationFailed("Unsupported authentication type")
|
||||||
@ -42,7 +42,7 @@ def token_from_header(raw_header: bytes) -> Optional[Token]:
|
|||||||
return tokens.first()
|
return tokens.first()
|
||||||
|
|
||||||
|
|
||||||
class AuthentikTokenAuthentication(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) -> Union[tuple[User, Any], None]:
|
35
authentik/api/authorization.py
Normal file
35
authentik/api/authorization.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
"""API Authorization"""
|
||||||
|
from django.db.models import Model
|
||||||
|
from django.db.models.query import QuerySet
|
||||||
|
from rest_framework.filters import BaseFilterBackend
|
||||||
|
from rest_framework.permissions import BasePermission
|
||||||
|
from rest_framework.request import Request
|
||||||
|
|
||||||
|
|
||||||
|
class OwnerFilter(BaseFilterBackend):
|
||||||
|
"""Filter objects by their owner"""
|
||||||
|
|
||||||
|
owner_key = "user"
|
||||||
|
|
||||||
|
def filter_queryset(self, request: Request, queryset: QuerySet, view) -> QuerySet:
|
||||||
|
return queryset.filter(**{self.owner_key: request.user})
|
||||||
|
|
||||||
|
|
||||||
|
class OwnerPermissions(BasePermission):
|
||||||
|
"""Authorize requests by an object's owner matching the requesting user"""
|
||||||
|
|
||||||
|
owner_key = "user"
|
||||||
|
|
||||||
|
def has_permission(self, request: Request, view) -> bool:
|
||||||
|
"""If the user is authenticated, we allow all requests here. For listing, the
|
||||||
|
object-level permissions are done by the filter backend"""
|
||||||
|
return request.user.is_authenticated
|
||||||
|
|
||||||
|
def has_object_permission(self, request: Request, view, obj: Model) -> bool:
|
||||||
|
"""Check if the object's owner matches the currently logged in user"""
|
||||||
|
if not hasattr(obj, self.owner_key):
|
||||||
|
return False
|
||||||
|
owner = getattr(obj, self.owner_key)
|
||||||
|
if owner != request.user:
|
||||||
|
return False
|
||||||
|
return True
|
@ -30,3 +30,47 @@ class Pagination(pagination.PageNumberPagination):
|
|||||||
"results": data,
|
"results": data,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_paginated_response_schema(self, schema):
|
||||||
|
return {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"pagination": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"next": {
|
||||||
|
"type": "number",
|
||||||
|
},
|
||||||
|
"previous": {
|
||||||
|
"type": "number",
|
||||||
|
},
|
||||||
|
"count": {
|
||||||
|
"type": "number",
|
||||||
|
},
|
||||||
|
"current": {
|
||||||
|
"type": "number",
|
||||||
|
},
|
||||||
|
"total_pages": {
|
||||||
|
"type": "number",
|
||||||
|
},
|
||||||
|
"start_index": {
|
||||||
|
"type": "number",
|
||||||
|
},
|
||||||
|
"end_index": {
|
||||||
|
"type": "number",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"next",
|
||||||
|
"previous",
|
||||||
|
"count",
|
||||||
|
"current",
|
||||||
|
"total_pages",
|
||||||
|
"start_index",
|
||||||
|
"end_index",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"results": schema,
|
||||||
|
},
|
||||||
|
"required": ["pagination", "results"],
|
||||||
|
}
|
||||||
|
@ -1,97 +0,0 @@
|
|||||||
"""Swagger Pagination Schema class"""
|
|
||||||
from typing import OrderedDict
|
|
||||||
|
|
||||||
from drf_yasg import openapi
|
|
||||||
from drf_yasg.inspectors import PaginatorInspector
|
|
||||||
|
|
||||||
|
|
||||||
class PaginationInspector(PaginatorInspector):
|
|
||||||
"""Swagger Pagination Schema class"""
|
|
||||||
|
|
||||||
def get_paginated_response(self, paginator, response_schema):
|
|
||||||
"""
|
|
||||||
:param BasePagination paginator: the paginator
|
|
||||||
:param openapi.Schema response_schema: the response schema that must be paged.
|
|
||||||
:rtype: openapi.Schema
|
|
||||||
"""
|
|
||||||
|
|
||||||
return openapi.Schema(
|
|
||||||
type=openapi.TYPE_OBJECT,
|
|
||||||
properties=OrderedDict(
|
|
||||||
(
|
|
||||||
(
|
|
||||||
"pagination",
|
|
||||||
openapi.Schema(
|
|
||||||
type=openapi.TYPE_OBJECT,
|
|
||||||
properties=OrderedDict(
|
|
||||||
(
|
|
||||||
("next", openapi.Schema(type=openapi.TYPE_NUMBER)),
|
|
||||||
(
|
|
||||||
"previous",
|
|
||||||
openapi.Schema(type=openapi.TYPE_NUMBER),
|
|
||||||
),
|
|
||||||
("count", openapi.Schema(type=openapi.TYPE_NUMBER)),
|
|
||||||
(
|
|
||||||
"current",
|
|
||||||
openapi.Schema(type=openapi.TYPE_NUMBER),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"total_pages",
|
|
||||||
openapi.Schema(type=openapi.TYPE_NUMBER),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"start_index",
|
|
||||||
openapi.Schema(type=openapi.TYPE_NUMBER),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"end_index",
|
|
||||||
openapi.Schema(type=openapi.TYPE_NUMBER),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
),
|
|
||||||
required=[
|
|
||||||
"next",
|
|
||||||
"previous",
|
|
||||||
"count",
|
|
||||||
"current",
|
|
||||||
"total_pages",
|
|
||||||
"start_index",
|
|
||||||
"end_index",
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
("results", response_schema),
|
|
||||||
)
|
|
||||||
),
|
|
||||||
required=["results", "pagination"],
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_paginator_parameters(self, paginator):
|
|
||||||
"""
|
|
||||||
Get the pagination parameters for a single paginator **instance**.
|
|
||||||
|
|
||||||
Should return :data:`.NotHandled` if this inspector
|
|
||||||
does not know how to handle the given `paginator`.
|
|
||||||
|
|
||||||
:param BasePagination paginator: the paginator
|
|
||||||
:rtype: list[openapi.Parameter]
|
|
||||||
"""
|
|
||||||
|
|
||||||
return [
|
|
||||||
openapi.Parameter(
|
|
||||||
"page",
|
|
||||||
openapi.IN_QUERY,
|
|
||||||
"Page Index",
|
|
||||||
False,
|
|
||||||
None,
|
|
||||||
openapi.TYPE_INTEGER,
|
|
||||||
),
|
|
||||||
openapi.Parameter(
|
|
||||||
"page_size",
|
|
||||||
openapi.IN_QUERY,
|
|
||||||
"Page Size",
|
|
||||||
False,
|
|
||||||
None,
|
|
||||||
openapi.TYPE_INTEGER,
|
|
||||||
),
|
|
||||||
]
|
|
@ -1,102 +1,77 @@
|
|||||||
"""Error Response schema, from https://github.com/axnsan12/drf-yasg/issues/224"""
|
"""Error Response schema, from https://github.com/axnsan12/drf-yasg/issues/224"""
|
||||||
from drf_yasg import openapi
|
from django.utils.translation import gettext_lazy as _
|
||||||
from drf_yasg.inspectors.view import SwaggerAutoSchema
|
from drf_spectacular.plumbing import (
|
||||||
from drf_yasg.utils import force_real_str, is_list_view
|
ResolvedComponent,
|
||||||
from rest_framework import exceptions, status
|
build_array_type,
|
||||||
from rest_framework.settings import api_settings
|
build_basic_type,
|
||||||
|
build_object_type,
|
||||||
|
)
|
||||||
|
from drf_spectacular.settings import spectacular_settings
|
||||||
|
from drf_spectacular.types import OpenApiTypes
|
||||||
|
|
||||||
|
|
||||||
class ErrorResponseAutoSchema(SwaggerAutoSchema):
|
def build_standard_type(obj, **kwargs):
|
||||||
"""Inspector which includes an error schema"""
|
"""Build a basic type with optional add ons."""
|
||||||
|
schema = build_basic_type(obj)
|
||||||
|
schema.update(kwargs)
|
||||||
|
return schema
|
||||||
|
|
||||||
def get_generic_error_schema(self):
|
|
||||||
"""Get a generic error schema"""
|
GENERIC_ERROR = build_object_type(
|
||||||
return openapi.Schema(
|
description=_("Generic API Error"),
|
||||||
"Generic API Error",
|
|
||||||
type=openapi.TYPE_OBJECT,
|
|
||||||
properties={
|
properties={
|
||||||
"detail": openapi.Schema(
|
"detail": build_standard_type(OpenApiTypes.STR),
|
||||||
type=openapi.TYPE_STRING, description="Error details"
|
"code": build_standard_type(OpenApiTypes.STR),
|
||||||
),
|
|
||||||
"code": openapi.Schema(
|
|
||||||
type=openapi.TYPE_STRING, description="Error code"
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
required=["detail"],
|
required=["detail"],
|
||||||
)
|
)
|
||||||
|
VALIDATION_ERROR = build_object_type(
|
||||||
def get_validation_error_schema(self):
|
description=_("Validation Error"),
|
||||||
"""Get a generic validation error schema"""
|
|
||||||
return openapi.Schema(
|
|
||||||
"Validation Error",
|
|
||||||
type=openapi.TYPE_OBJECT,
|
|
||||||
properties={
|
properties={
|
||||||
api_settings.NON_FIELD_ERRORS_KEY: openapi.Schema(
|
"non_field_errors": build_array_type(build_standard_type(OpenApiTypes.STR)),
|
||||||
description="List of validation errors not related to any field",
|
"code": build_standard_type(OpenApiTypes.STR),
|
||||||
type=openapi.TYPE_ARRAY,
|
|
||||||
items=openapi.Schema(type=openapi.TYPE_STRING),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
additional_properties=openapi.Schema(
|
required=["detail"],
|
||||||
description=(
|
additionalProperties={},
|
||||||
"A list of error messages for each "
|
)
|
||||||
"field that triggered a validation error"
|
|
||||||
),
|
|
||||||
type=openapi.TYPE_ARRAY,
|
def postprocess_schema_responses(result, generator, **kwargs): # noqa: W0613
|
||||||
items=openapi.Schema(type=openapi.TYPE_STRING),
|
"""Workaround to set a default response for endpoints.
|
||||||
),
|
Workaround suggested at
|
||||||
|
<https://github.com/tfranzel/drf-spectacular/issues/119#issuecomment-656970357>
|
||||||
|
for the missing drf-spectacular feature discussed in
|
||||||
|
<https://github.com/tfranzel/drf-spectacular/issues/101>.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def create_component(name, schema, type_=ResolvedComponent.SCHEMA):
|
||||||
|
"""Register a component and return a reference to it."""
|
||||||
|
component = ResolvedComponent(
|
||||||
|
name=name,
|
||||||
|
type=type_,
|
||||||
|
schema=schema,
|
||||||
|
object=name,
|
||||||
|
)
|
||||||
|
generator.registry.register_on_missing(component)
|
||||||
|
return component
|
||||||
|
|
||||||
|
generic_error = create_component("GenericError", GENERIC_ERROR)
|
||||||
|
validation_error = create_component("ValidationError", VALIDATION_ERROR)
|
||||||
|
|
||||||
|
for path in result["paths"].values():
|
||||||
|
for method in path.values():
|
||||||
|
method["responses"].setdefault("400", validation_error.ref)
|
||||||
|
method["responses"].setdefault("403", generic_error.ref)
|
||||||
|
|
||||||
|
result["components"] = generator.registry.build(
|
||||||
|
spectacular_settings.APPEND_COMPONENTS
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_response_serializers(self):
|
# This is a workaround for authentik/stages/prompt/stage.py
|
||||||
responses = super().get_response_serializers()
|
# since the serializer PromptChallengeResponse
|
||||||
definitions = self.components.with_scope(
|
# accepts dynamic keys
|
||||||
openapi.SCHEMA_DEFINITIONS
|
for component in result["components"]["schemas"]:
|
||||||
) # type: openapi.ReferenceResolver
|
if component == "PromptChallengeResponseRequest":
|
||||||
|
comp = result["components"]["schemas"][component]
|
||||||
definitions.setdefault("GenericError", self.get_generic_error_schema)
|
comp["additionalProperties"] = {}
|
||||||
definitions.setdefault("ValidationError", self.get_validation_error_schema)
|
return result
|
||||||
definitions.setdefault("APIException", self.get_generic_error_schema)
|
|
||||||
|
|
||||||
if self.get_request_serializer() or self.get_query_serializer():
|
|
||||||
responses.setdefault(
|
|
||||||
exceptions.ValidationError.status_code,
|
|
||||||
openapi.Response(
|
|
||||||
description=force_real_str(
|
|
||||||
exceptions.ValidationError.default_detail
|
|
||||||
),
|
|
||||||
schema=openapi.SchemaRef(definitions, "ValidationError"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
security = self.get_security()
|
|
||||||
if security is None or len(security) > 0:
|
|
||||||
# Note: 401 error codes are coerced into 403 see
|
|
||||||
# rest_framework/views.py:433:handle_exception
|
|
||||||
# This is b/c the API uses token auth which doesn't have WWW-Authenticate header
|
|
||||||
responses.setdefault(
|
|
||||||
status.HTTP_403_FORBIDDEN,
|
|
||||||
openapi.Response(
|
|
||||||
description="Authentication credentials were invalid, absent or insufficient.",
|
|
||||||
schema=openapi.SchemaRef(definitions, "GenericError"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
if not is_list_view(self.path, self.method, self.view):
|
|
||||||
responses.setdefault(
|
|
||||||
exceptions.PermissionDenied.status_code,
|
|
||||||
openapi.Response(
|
|
||||||
description="Permission denied.",
|
|
||||||
schema=openapi.SchemaRef(definitions, "APIException"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
responses.setdefault(
|
|
||||||
exceptions.NotFound.status_code,
|
|
||||||
openapi.Response(
|
|
||||||
description=(
|
|
||||||
"Object does not exist or caller "
|
|
||||||
"has insufficient permissions to access it."
|
|
||||||
),
|
|
||||||
schema=openapi.SchemaRef(definitions, "APIException"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
return responses
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
{% load static %}
|
{% load static %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
API Browser - {{ config.authentik.branding.title }}
|
API Browser - {{ tenant.branding_title }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block head %}
|
{% block head %}
|
@ -5,7 +5,7 @@ from django.test import TestCase
|
|||||||
from guardian.shortcuts import get_anonymous_user
|
from guardian.shortcuts import get_anonymous_user
|
||||||
from rest_framework.exceptions import AuthenticationFailed
|
from rest_framework.exceptions import AuthenticationFailed
|
||||||
|
|
||||||
from authentik.api.auth import token_from_header
|
from authentik.api.authentication import token_from_header
|
||||||
from authentik.core.models import Token, TokenIntents
|
from authentik.core.models import Token, TokenIntents
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,6 +11,6 @@ class TestConfig(APITestCase):
|
|||||||
def test_config(self):
|
def test_config(self):
|
||||||
"""Test YAML generation"""
|
"""Test YAML generation"""
|
||||||
response = self.client.get(
|
response = self.client.get(
|
||||||
reverse("authentik_api:configs-list"),
|
reverse("authentik_api:config"),
|
||||||
)
|
)
|
||||||
self.assertTrue(loads(response.content.decode()))
|
self.assertTrue(loads(response.content.decode()))
|
||||||
|
22
authentik/api/tests/test_schema.py
Normal file
22
authentik/api/tests/test_schema.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
"""Schema generation tests"""
|
||||||
|
from django.urls import reverse
|
||||||
|
from rest_framework.test import APITestCase
|
||||||
|
from yaml import safe_load
|
||||||
|
|
||||||
|
|
||||||
|
class TestSchemaGeneration(APITestCase):
|
||||||
|
"""Generic admin tests"""
|
||||||
|
|
||||||
|
def test_schema(self):
|
||||||
|
"""Test generation"""
|
||||||
|
response = self.client.get(
|
||||||
|
reverse("authentik_api:schema"),
|
||||||
|
)
|
||||||
|
self.assertTrue(safe_load(response.content.decode()))
|
||||||
|
|
||||||
|
def test_browser(self):
|
||||||
|
"""Test API Browser"""
|
||||||
|
response = self.client.get(
|
||||||
|
reverse("authentik_api:schema-browser"),
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
@ -1,31 +0,0 @@
|
|||||||
"""Swagger generation tests"""
|
|
||||||
from json import loads
|
|
||||||
|
|
||||||
from django.urls import reverse
|
|
||||||
from rest_framework.test import APITestCase
|
|
||||||
from yaml import safe_load
|
|
||||||
|
|
||||||
|
|
||||||
class TestSwaggerGeneration(APITestCase):
|
|
||||||
"""Generic admin tests"""
|
|
||||||
|
|
||||||
def test_yaml(self):
|
|
||||||
"""Test YAML generation"""
|
|
||||||
response = self.client.get(
|
|
||||||
reverse("authentik_api:schema-json", kwargs={"format": ".yaml"}),
|
|
||||||
)
|
|
||||||
self.assertTrue(safe_load(response.content.decode()))
|
|
||||||
|
|
||||||
def test_json(self):
|
|
||||||
"""Test JSON generation"""
|
|
||||||
response = self.client.get(
|
|
||||||
reverse("authentik_api:schema-json", kwargs={"format": ".json"}),
|
|
||||||
)
|
|
||||||
self.assertTrue(loads(response.content.decode()))
|
|
||||||
|
|
||||||
def test_browser(self):
|
|
||||||
"""Test API Browser"""
|
|
||||||
response = self.client.get(
|
|
||||||
reverse("authentik_api:swagger"),
|
|
||||||
)
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
@ -1,50 +1,70 @@
|
|||||||
"""core Configs API"""
|
"""core Configs API"""
|
||||||
from drf_yasg.utils import swagger_auto_schema
|
from os import environ, path
|
||||||
from rest_framework.fields import BooleanField, CharField, ListField
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import models
|
||||||
|
from drf_spectacular.utils import extend_schema
|
||||||
|
from kubernetes.config.incluster_config import SERVICE_HOST_ENV_NAME
|
||||||
|
from rest_framework.fields import BooleanField, CharField, ChoiceField, ListField
|
||||||
from rest_framework.permissions import AllowAny
|
from rest_framework.permissions import AllowAny
|
||||||
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.views import APIView
|
||||||
|
|
||||||
from authentik.core.api.utils import PassiveSerializer
|
from authentik.core.api.utils import PassiveSerializer
|
||||||
|
from authentik.events.geo import GEOIP_READER
|
||||||
from authentik.lib.config import CONFIG
|
from authentik.lib.config import CONFIG
|
||||||
|
|
||||||
|
|
||||||
class FooterLinkSerializer(PassiveSerializer):
|
class Capabilities(models.TextChoices):
|
||||||
"""Links returned in Config API"""
|
"""Define capabilities which influence which APIs can/should be used"""
|
||||||
|
|
||||||
href = CharField(read_only=True)
|
CAN_SAVE_MEDIA = "can_save_media"
|
||||||
name = CharField(read_only=True)
|
CAN_GEO_IP = "can_geo_ip"
|
||||||
|
CAN_BACKUP = "can_backup"
|
||||||
|
|
||||||
|
|
||||||
class ConfigSerializer(PassiveSerializer):
|
class ConfigSerializer(PassiveSerializer):
|
||||||
"""Serialize authentik Config into DRF Object"""
|
"""Serialize authentik Config into DRF Object"""
|
||||||
|
|
||||||
branding_logo = CharField(read_only=True)
|
|
||||||
branding_title = CharField(read_only=True)
|
|
||||||
ui_footer_links = ListField(child=FooterLinkSerializer(), read_only=True)
|
|
||||||
|
|
||||||
error_reporting_enabled = BooleanField(read_only=True)
|
error_reporting_enabled = BooleanField(read_only=True)
|
||||||
error_reporting_environment = CharField(read_only=True)
|
error_reporting_environment = CharField(read_only=True)
|
||||||
error_reporting_send_pii = BooleanField(read_only=True)
|
error_reporting_send_pii = BooleanField(read_only=True)
|
||||||
|
|
||||||
|
capabilities = ListField(child=ChoiceField(choices=Capabilities.choices))
|
||||||
|
|
||||||
class ConfigsViewSet(ViewSet):
|
|
||||||
|
class ConfigView(APIView):
|
||||||
"""Read-only view set that returns the current session's Configs"""
|
"""Read-only view set that returns the current session's Configs"""
|
||||||
|
|
||||||
permission_classes = [AllowAny]
|
permission_classes = [AllowAny]
|
||||||
|
|
||||||
@swagger_auto_schema(responses={200: ConfigSerializer(many=False)})
|
def get_capabilities(self) -> list[Capabilities]:
|
||||||
def list(self, request: Request) -> Response:
|
"""Get all capabilities this server instance supports"""
|
||||||
|
caps = []
|
||||||
|
deb_test = settings.DEBUG or settings.TEST
|
||||||
|
if path.ismount(settings.MEDIA_ROOT) or deb_test:
|
||||||
|
caps.append(Capabilities.CAN_SAVE_MEDIA)
|
||||||
|
if GEOIP_READER.enabled:
|
||||||
|
caps.append(Capabilities.CAN_GEO_IP)
|
||||||
|
if SERVICE_HOST_ENV_NAME in environ:
|
||||||
|
# Running in k8s, only s3 backup is supported
|
||||||
|
if CONFIG.y_bool("postgresql.s3_backup"):
|
||||||
|
caps.append(Capabilities.CAN_BACKUP)
|
||||||
|
else:
|
||||||
|
# Running in compose, backup is always supported
|
||||||
|
caps.append(Capabilities.CAN_BACKUP)
|
||||||
|
return caps
|
||||||
|
|
||||||
|
@extend_schema(responses={200: ConfigSerializer(many=False)})
|
||||||
|
def get(self, request: Request) -> Response:
|
||||||
"""Retrive public configuration options"""
|
"""Retrive public configuration options"""
|
||||||
config = ConfigSerializer(
|
config = ConfigSerializer(
|
||||||
{
|
{
|
||||||
"branding_logo": CONFIG.y("authentik.branding.logo"),
|
|
||||||
"branding_title": CONFIG.y("authentik.branding.title"),
|
|
||||||
"error_reporting_enabled": CONFIG.y("error_reporting.enabled"),
|
"error_reporting_enabled": CONFIG.y("error_reporting.enabled"),
|
||||||
"error_reporting_environment": CONFIG.y("error_reporting.environment"),
|
"error_reporting_environment": CONFIG.y("error_reporting.environment"),
|
||||||
"error_reporting_send_pii": CONFIG.y("error_reporting.send_pii"),
|
"error_reporting_send_pii": CONFIG.y("error_reporting.send_pii"),
|
||||||
"ui_footer_links": CONFIG.y("authentik.footer_links"),
|
"capabilities": self.get_capabilities(),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return Response(config.data)
|
return Response(config.data)
|
||||||
|
38
authentik/api/v2/sentry.py
Normal file
38
authentik/api/v2/sentry.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
"""Sentry tunnel"""
|
||||||
|
from json import loads
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.http.request import HttpRequest
|
||||||
|
from django.http.response import HttpResponse
|
||||||
|
from django.views.generic.base import View
|
||||||
|
from requests import post
|
||||||
|
from requests.exceptions import RequestException
|
||||||
|
|
||||||
|
from authentik.lib.config import CONFIG
|
||||||
|
|
||||||
|
|
||||||
|
class SentryTunnelView(View):
|
||||||
|
"""Sentry tunnel, to prevent ad blockers from blocking sentry"""
|
||||||
|
|
||||||
|
def post(self, request: HttpRequest, *args, **kwargs) -> HttpResponse:
|
||||||
|
"""Sentry tunnel, to prevent ad blockers from blocking sentry"""
|
||||||
|
# Only allow usage of this endpoint when error reporting is enabled
|
||||||
|
if not CONFIG.y_bool("error_reporting.enabled", False):
|
||||||
|
return HttpResponse(status=400)
|
||||||
|
# Body is 2 json objects separated by \n
|
||||||
|
full_body = request.body
|
||||||
|
header = loads(full_body.splitlines()[0])
|
||||||
|
# Check that the DSN is what we expect
|
||||||
|
dsn = header.get("dsn", "")
|
||||||
|
if dsn != settings.SENTRY_DSN:
|
||||||
|
return HttpResponse(status=400)
|
||||||
|
response = post(
|
||||||
|
"https://sentry.beryju.org/api/8/envelope/",
|
||||||
|
data=full_body,
|
||||||
|
headers={"Content-Type": "application/octet-stream"},
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
response.raise_for_status()
|
||||||
|
except RequestException:
|
||||||
|
return HttpResponse(status=500)
|
||||||
|
return HttpResponse(status=response.status_code)
|
@ -1,18 +1,20 @@
|
|||||||
"""api v2 urls"""
|
"""api v2 urls"""
|
||||||
from django.urls import path, re_path
|
from django.urls import path
|
||||||
from drf_yasg import openapi
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from drf_yasg.views import get_schema_view
|
from drf_spectacular.views import SpectacularAPIView
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
from rest_framework.permissions import AllowAny
|
|
||||||
|
|
||||||
from authentik.admin.api.meta import AppsViewSet
|
from authentik.admin.api.meta import AppsViewSet
|
||||||
from authentik.admin.api.metrics import AdministrationMetricsViewSet
|
from authentik.admin.api.metrics import AdministrationMetricsViewSet
|
||||||
|
from authentik.admin.api.system import SystemView
|
||||||
from authentik.admin.api.tasks import TaskViewSet
|
from authentik.admin.api.tasks import TaskViewSet
|
||||||
from authentik.admin.api.version import VersionViewSet
|
from authentik.admin.api.version import VersionView
|
||||||
from authentik.admin.api.workers import WorkerViewSet
|
from authentik.admin.api.workers import WorkerView
|
||||||
from authentik.api.v2.config import ConfigsViewSet
|
from authentik.api.v2.config import ConfigView
|
||||||
from authentik.api.views import SwaggerView
|
from authentik.api.v2.sentry import SentryTunnelView
|
||||||
|
from authentik.api.views import APIBrowserView
|
||||||
from authentik.core.api.applications import ApplicationViewSet
|
from authentik.core.api.applications import ApplicationViewSet
|
||||||
|
from authentik.core.api.authenticated_sessions import AuthenticatedSessionViewSet
|
||||||
from authentik.core.api.groups import GroupViewSet
|
from authentik.core.api.groups import GroupViewSet
|
||||||
from authentik.core.api.propertymappings import PropertyMappingViewSet
|
from authentik.core.api.propertymappings import PropertyMappingViewSet
|
||||||
from authentik.core.api.providers import ProviderViewSet
|
from authentik.core.api.providers import ProviderViewSet
|
||||||
@ -28,12 +30,12 @@ from authentik.flows.api.bindings import FlowStageBindingViewSet
|
|||||||
from authentik.flows.api.flows import FlowViewSet
|
from authentik.flows.api.flows import FlowViewSet
|
||||||
from authentik.flows.api.stages import StageViewSet
|
from authentik.flows.api.stages import StageViewSet
|
||||||
from authentik.flows.views import FlowExecutorView
|
from authentik.flows.views import FlowExecutorView
|
||||||
from authentik.outposts.api.outpost_service_connections import (
|
from authentik.outposts.api.outposts import OutpostViewSet
|
||||||
|
from authentik.outposts.api.service_connections import (
|
||||||
DockerServiceConnectionViewSet,
|
DockerServiceConnectionViewSet,
|
||||||
KubernetesServiceConnectionViewSet,
|
KubernetesServiceConnectionViewSet,
|
||||||
ServiceConnectionViewSet,
|
ServiceConnectionViewSet,
|
||||||
)
|
)
|
||||||
from authentik.outposts.api.outposts import OutpostViewSet
|
|
||||||
from authentik.policies.api.bindings import PolicyBindingViewSet
|
from authentik.policies.api.bindings import PolicyBindingViewSet
|
||||||
from authentik.policies.api.policies import PolicyViewSet
|
from authentik.policies.api.policies import PolicyViewSet
|
||||||
from authentik.policies.dummy.api import DummyPolicyViewSet
|
from authentik.policies.dummy.api import DummyPolicyViewSet
|
||||||
@ -66,6 +68,11 @@ from authentik.sources.oauth.api.source_connection import (
|
|||||||
)
|
)
|
||||||
from authentik.sources.plex.api import PlexSourceViewSet
|
from authentik.sources.plex.api import PlexSourceViewSet
|
||||||
from authentik.sources.saml.api import SAMLSourceViewSet
|
from authentik.sources.saml.api import SAMLSourceViewSet
|
||||||
|
from authentik.stages.authenticator_duo.api import (
|
||||||
|
AuthenticatorDuoStageViewSet,
|
||||||
|
DuoAdminDeviceViewSet,
|
||||||
|
DuoDeviceViewSet,
|
||||||
|
)
|
||||||
from authentik.stages.authenticator_static.api import (
|
from authentik.stages.authenticator_static.api import (
|
||||||
AuthenticatorStaticStageViewSet,
|
AuthenticatorStaticStageViewSet,
|
||||||
StaticAdminDeviceViewSet,
|
StaticAdminDeviceViewSet,
|
||||||
@ -97,24 +104,21 @@ from authentik.stages.user_delete.api import UserDeleteStageViewSet
|
|||||||
from authentik.stages.user_login.api import UserLoginStageViewSet
|
from authentik.stages.user_login.api import UserLoginStageViewSet
|
||||||
from authentik.stages.user_logout.api import UserLogoutStageViewSet
|
from authentik.stages.user_logout.api import UserLogoutStageViewSet
|
||||||
from authentik.stages.user_write.api import UserWriteStageViewSet
|
from authentik.stages.user_write.api import UserWriteStageViewSet
|
||||||
|
from authentik.tenants.api import TenantViewSet
|
||||||
|
|
||||||
router = routers.DefaultRouter()
|
router = routers.DefaultRouter()
|
||||||
|
|
||||||
router.register("root/config", ConfigsViewSet, basename="configs")
|
|
||||||
|
|
||||||
router.register("admin/version", VersionViewSet, basename="admin_version")
|
|
||||||
router.register("admin/workers", WorkerViewSet, basename="admin_workers")
|
|
||||||
router.register("admin/metrics", AdministrationMetricsViewSet, basename="admin_metrics")
|
|
||||||
router.register("admin/system_tasks", TaskViewSet, basename="admin_system_tasks")
|
router.register("admin/system_tasks", TaskViewSet, basename="admin_system_tasks")
|
||||||
router.register("admin/apps", AppsViewSet, basename="apps")
|
router.register("admin/apps", AppsViewSet, basename="apps")
|
||||||
|
|
||||||
|
router.register("core/authenticated_sessions", AuthenticatedSessionViewSet)
|
||||||
router.register("core/applications", ApplicationViewSet)
|
router.register("core/applications", ApplicationViewSet)
|
||||||
router.register("core/groups", GroupViewSet)
|
router.register("core/groups", GroupViewSet)
|
||||||
router.register("core/users", UserViewSet)
|
router.register("core/users", UserViewSet)
|
||||||
router.register("core/user_consent", UserConsentViewSet)
|
router.register("core/user_consent", UserConsentViewSet)
|
||||||
router.register("core/tokens", TokenViewSet)
|
router.register("core/tokens", TokenViewSet)
|
||||||
|
router.register("core/tenants", TenantViewSet)
|
||||||
|
|
||||||
router.register("outposts/outposts", OutpostViewSet)
|
|
||||||
router.register("outposts/instances", OutpostViewSet)
|
router.register("outposts/instances", OutpostViewSet)
|
||||||
router.register("outposts/service_connections/all", ServiceConnectionViewSet)
|
router.register("outposts/service_connections/all", ServiceConnectionViewSet)
|
||||||
router.register("outposts/service_connections/docker", DockerServiceConnectionViewSet)
|
router.register("outposts/service_connections/docker", DockerServiceConnectionViewSet)
|
||||||
@ -166,14 +170,31 @@ router.register("propertymappings/ldap", LDAPPropertyMappingViewSet)
|
|||||||
router.register("propertymappings/saml", SAMLPropertyMappingViewSet)
|
router.register("propertymappings/saml", SAMLPropertyMappingViewSet)
|
||||||
router.register("propertymappings/scope", ScopeMappingViewSet)
|
router.register("propertymappings/scope", ScopeMappingViewSet)
|
||||||
|
|
||||||
|
router.register("authenticators/duo", DuoDeviceViewSet)
|
||||||
router.register("authenticators/static", StaticDeviceViewSet)
|
router.register("authenticators/static", StaticDeviceViewSet)
|
||||||
router.register("authenticators/totp", TOTPDeviceViewSet)
|
router.register("authenticators/totp", TOTPDeviceViewSet)
|
||||||
router.register("authenticators/webauthn", WebAuthnDeviceViewSet)
|
router.register("authenticators/webauthn", WebAuthnDeviceViewSet)
|
||||||
router.register("authenticators/admin/static", StaticAdminDeviceViewSet)
|
router.register(
|
||||||
router.register("authenticators/admin/totp", TOTPAdminDeviceViewSet)
|
"authenticators/admin/duo",
|
||||||
router.register("authenticators/admin/webauthn", WebAuthnAdminDeviceViewSet)
|
DuoAdminDeviceViewSet,
|
||||||
|
basename="admin-duodevice",
|
||||||
|
)
|
||||||
|
router.register(
|
||||||
|
"authenticators/admin/static",
|
||||||
|
StaticAdminDeviceViewSet,
|
||||||
|
basename="admin-staticdevice",
|
||||||
|
)
|
||||||
|
router.register(
|
||||||
|
"authenticators/admin/totp", TOTPAdminDeviceViewSet, basename="admin-totpdevice"
|
||||||
|
)
|
||||||
|
router.register(
|
||||||
|
"authenticators/admin/webauthn",
|
||||||
|
WebAuthnAdminDeviceViewSet,
|
||||||
|
basename="admin-webauthndevice",
|
||||||
|
)
|
||||||
|
|
||||||
router.register("stages/all", StageViewSet)
|
router.register("stages/all", StageViewSet)
|
||||||
|
router.register("stages/authenticator/duo", AuthenticatorDuoStageViewSet)
|
||||||
router.register("stages/authenticator/static", AuthenticatorStaticStageViewSet)
|
router.register("stages/authenticator/static", AuthenticatorStaticStageViewSet)
|
||||||
router.register("stages/authenticator/totp", AuthenticatorTOTPStageViewSet)
|
router.register("stages/authenticator/totp", AuthenticatorTOTPStageViewSet)
|
||||||
router.register("stages/authenticator/validate", AuthenticatorValidateStageViewSet)
|
router.register("stages/authenticator/validate", AuthenticatorValidateStageViewSet)
|
||||||
@ -196,32 +217,27 @@ router.register("stages/user_write", UserWriteStageViewSet)
|
|||||||
router.register("stages/dummy", DummyStageViewSet)
|
router.register("stages/dummy", DummyStageViewSet)
|
||||||
router.register("policies/dummy", DummyPolicyViewSet)
|
router.register("policies/dummy", DummyPolicyViewSet)
|
||||||
|
|
||||||
info = openapi.Info(
|
|
||||||
title="authentik API",
|
|
||||||
default_version="v2beta",
|
|
||||||
contact=openapi.Contact(email="hello@beryju.org"),
|
|
||||||
license=openapi.License(
|
|
||||||
name="GNU GPLv3",
|
|
||||||
url="https://github.com/goauthentik/authentik/blob/master/LICENSE",
|
|
||||||
),
|
|
||||||
)
|
|
||||||
SchemaView = get_schema_view(info, public=True, permission_classes=(AllowAny,))
|
|
||||||
|
|
||||||
urlpatterns = (
|
urlpatterns = (
|
||||||
[
|
[
|
||||||
path("", SwaggerView.as_view(), name="swagger"),
|
path("", APIBrowserView.as_view(), name="schema-browser"),
|
||||||
]
|
]
|
||||||
+ router.urls
|
+ router.urls
|
||||||
+ [
|
+ [
|
||||||
|
path(
|
||||||
|
"admin/metrics/",
|
||||||
|
AdministrationMetricsViewSet.as_view(),
|
||||||
|
name="admin_metrics",
|
||||||
|
),
|
||||||
|
path("admin/version/", VersionView.as_view(), name="admin_version"),
|
||||||
|
path("admin/workers/", WorkerView.as_view(), name="admin_workers"),
|
||||||
|
path("admin/system/", SystemView.as_view(), name="admin_system"),
|
||||||
|
path("root/config/", ConfigView.as_view(), name="config"),
|
||||||
path(
|
path(
|
||||||
"flows/executor/<slug:flow_slug>/",
|
"flows/executor/<slug:flow_slug>/",
|
||||||
FlowExecutorView.as_view(),
|
FlowExecutorView.as_view(),
|
||||||
name="flow-executor",
|
name="flow-executor",
|
||||||
),
|
),
|
||||||
re_path(
|
path("sentry/", csrf_exempt(SentryTunnelView.as_view()), name="sentry"),
|
||||||
r"^swagger(?P<format>\.json|\.yaml)$",
|
path("schema/", SpectacularAPIView.as_view(), name="schema"),
|
||||||
SchemaView.without_ui(cache_timeout=0),
|
|
||||||
name="schema-json",
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
@ -5,18 +5,15 @@ from django.urls import reverse
|
|||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
|
|
||||||
|
|
||||||
class SwaggerView(TemplateView):
|
class APIBrowserView(TemplateView):
|
||||||
"""Show swagger view based on rapi-doc"""
|
"""Show browser view based on rapi-doc"""
|
||||||
|
|
||||||
template_name = "api/swagger.html"
|
template_name = "api/browser.html"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
|
def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
|
||||||
path = self.request.build_absolute_uri(
|
path = self.request.build_absolute_uri(
|
||||||
reverse(
|
reverse(
|
||||||
"authentik_api:schema-json",
|
"authentik_api:schema",
|
||||||
kwargs={
|
|
||||||
"format": ".json",
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return super().get_context_data(path=path, **kwargs)
|
return super().get_context_data(path=path, **kwargs)
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
"""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
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from drf_yasg import openapi
|
from drf_spectacular.types import OpenApiTypes
|
||||||
from drf_yasg.utils import no_body, swagger_auto_schema
|
from drf_spectacular.utils import (
|
||||||
|
OpenApiParameter,
|
||||||
|
OpenApiResponse,
|
||||||
|
extend_schema,
|
||||||
|
inline_serializer,
|
||||||
|
)
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.fields import SerializerMethodField
|
from rest_framework.fields import BooleanField, CharField, FileField, ReadOnlyField
|
||||||
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
|
||||||
@ -20,9 +23,13 @@ from structlog.stdlib import get_logger
|
|||||||
from authentik.admin.api.metrics import CoordinateSerializer, get_events_per_1h
|
from authentik.admin.api.metrics import CoordinateSerializer, get_events_per_1h
|
||||||
from authentik.api.decorators import permission_required
|
from authentik.api.decorators import permission_required
|
||||||
from authentik.core.api.providers import ProviderSerializer
|
from authentik.core.api.providers import ProviderSerializer
|
||||||
from authentik.core.models import Application
|
from authentik.core.api.used_by import UsedByMixin
|
||||||
|
from authentik.core.models import Application, User
|
||||||
from authentik.events.models import EventAction
|
from authentik.events.models import EventAction
|
||||||
|
from authentik.policies.api.exec import PolicyTestResultSerializer
|
||||||
from authentik.policies.engine import PolicyEngine
|
from authentik.policies.engine import PolicyEngine
|
||||||
|
from authentik.policies.types import PolicyResult
|
||||||
|
from authentik.stages.user_login.stage import USER_LOGIN_AUTHENTICATED
|
||||||
|
|
||||||
LOGGER = get_logger()
|
LOGGER = get_logger()
|
||||||
|
|
||||||
@ -35,12 +42,10 @@ def user_app_cache_key(user_pk: str) -> str:
|
|||||||
class ApplicationSerializer(ModelSerializer):
|
class ApplicationSerializer(ModelSerializer):
|
||||||
"""Application Serializer"""
|
"""Application Serializer"""
|
||||||
|
|
||||||
launch_url = SerializerMethodField()
|
launch_url = ReadOnlyField(source="get_launch_url")
|
||||||
provider_obj = ProviderSerializer(source="get_provider", required=False)
|
provider_obj = ProviderSerializer(source="get_provider", required=False)
|
||||||
|
|
||||||
def get_launch_url(self, instance: Application) -> Optional[str]:
|
meta_icon = ReadOnlyField(source="get_meta_icon")
|
||||||
"""Get generated launch URL"""
|
|
||||||
return instance.get_launch_url()
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
||||||
@ -58,9 +63,12 @@ class ApplicationSerializer(ModelSerializer):
|
|||||||
"meta_publisher",
|
"meta_publisher",
|
||||||
"policy_engine_mode",
|
"policy_engine_mode",
|
||||||
]
|
]
|
||||||
|
extra_kwargs = {
|
||||||
|
"meta_icon": {"read_only": True},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class ApplicationViewSet(ModelViewSet):
|
class ApplicationViewSet(UsedByMixin, ModelViewSet):
|
||||||
"""Application Viewset"""
|
"""Application Viewset"""
|
||||||
|
|
||||||
queryset = Application.objects.all()
|
queryset = Application.objects.all()
|
||||||
@ -92,47 +100,65 @@ class ApplicationViewSet(ModelViewSet):
|
|||||||
applications.append(application)
|
applications.append(application)
|
||||||
return applications
|
return applications
|
||||||
|
|
||||||
@swagger_auto_schema(
|
@extend_schema(
|
||||||
|
parameters=[
|
||||||
|
OpenApiParameter(
|
||||||
|
name="for_user",
|
||||||
|
location=OpenApiParameter.QUERY,
|
||||||
|
type=OpenApiTypes.INT,
|
||||||
|
)
|
||||||
|
],
|
||||||
responses={
|
responses={
|
||||||
204: "Access granted",
|
200: PolicyTestResultSerializer(),
|
||||||
403: "Access denied",
|
404: OpenApiResponse(description="for_user user not found"),
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
@action(detail=True, methods=["GET"])
|
@action(detail=True, methods=["GET"])
|
||||||
# pylint: disable=unused-argument
|
|
||||||
def check_access(self, request: Request, slug: str) -> Response:
|
def check_access(self, request: Request, slug: str) -> Response:
|
||||||
"""Check access to a single application by slug"""
|
"""Check access to a single application by slug"""
|
||||||
# Don't use self.get_object as that checks for view_application permission
|
# Don't use self.get_object as that checks for view_application permission
|
||||||
# which the user might not have, even if they have access
|
# which the user might not have, even if they have access
|
||||||
application = get_object_or_404(Application, slug=slug)
|
application = get_object_or_404(Application, slug=slug)
|
||||||
engine = PolicyEngine(application, self.request.user, self.request)
|
# If the current user is superuser, they can set `for_user`
|
||||||
|
for_user = request.user
|
||||||
|
if request.user.is_superuser and "for_user" in request.query_params:
|
||||||
|
for_user = get_object_or_404(User, pk=request.query_params.get("for_user"))
|
||||||
|
engine = PolicyEngine(application, for_user, request)
|
||||||
|
engine.use_cache = False
|
||||||
engine.build()
|
engine.build()
|
||||||
if engine.passing:
|
result = engine.result
|
||||||
return Response(status=204)
|
response = PolicyTestResultSerializer(PolicyResult(False))
|
||||||
return Response(status=403)
|
if result.passing:
|
||||||
|
response = PolicyTestResultSerializer(PolicyResult(True))
|
||||||
|
if request.user.is_superuser:
|
||||||
|
response = PolicyTestResultSerializer(result)
|
||||||
|
return Response(response.data)
|
||||||
|
|
||||||
@swagger_auto_schema(
|
@extend_schema(
|
||||||
manual_parameters=[
|
parameters=[
|
||||||
openapi.Parameter(
|
OpenApiParameter(
|
||||||
name="superuser_full_list",
|
name="superuser_full_list",
|
||||||
in_=openapi.IN_QUERY,
|
location=OpenApiParameter.QUERY,
|
||||||
type=openapi.TYPE_BOOLEAN,
|
type=OpenApiTypes.BOOL,
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def list(self, request: Request) -> Response:
|
def list(self, request: Request) -> Response:
|
||||||
"""Custom list method that checks Policy based access instead of guardian"""
|
"""Custom list method that checks Policy based access instead of guardian"""
|
||||||
queryset = self._filter_queryset_for_list(self.get_queryset())
|
|
||||||
self.paginate_queryset(queryset)
|
|
||||||
|
|
||||||
should_cache = request.GET.get("search", "") == ""
|
should_cache = request.GET.get("search", "") == ""
|
||||||
|
|
||||||
superuser_full_list = (
|
superuser_full_list = (
|
||||||
str(request.GET.get("superuser_full_list", "false")).lower() == "true"
|
str(request.GET.get("superuser_full_list", "false")).lower() == "true"
|
||||||
)
|
)
|
||||||
if superuser_full_list and request.user.is_superuser:
|
if superuser_full_list and request.user.is_superuser:
|
||||||
serializer = self.get_serializer(queryset, many=True)
|
return super().list(request)
|
||||||
return self.get_paginated_response(serializer.data)
|
|
||||||
|
# To prevent the user from having to double login when prompt is set to login
|
||||||
|
# and the user has just signed it. This session variable is set in the UserLoginStage
|
||||||
|
# and is (quite hackily) removed from the session in applications's API's List method
|
||||||
|
self.request.session.pop(USER_LOGIN_AUTHENTICATED, None)
|
||||||
|
queryset = self._filter_queryset_for_list(self.get_queryset())
|
||||||
|
self.paginate_queryset(queryset)
|
||||||
|
|
||||||
allowed_applications = []
|
allowed_applications = []
|
||||||
if not should_cache:
|
if not should_cache:
|
||||||
@ -151,17 +177,20 @@ class ApplicationViewSet(ModelViewSet):
|
|||||||
return self.get_paginated_response(serializer.data)
|
return self.get_paginated_response(serializer.data)
|
||||||
|
|
||||||
@permission_required("authentik_core.change_application")
|
@permission_required("authentik_core.change_application")
|
||||||
@swagger_auto_schema(
|
@extend_schema(
|
||||||
request_body=no_body,
|
request={
|
||||||
manual_parameters=[
|
"multipart/form-data": inline_serializer(
|
||||||
openapi.Parameter(
|
"SetIcon",
|
||||||
name="file",
|
fields={
|
||||||
in_=openapi.IN_FORM,
|
"file": FileField(required=False),
|
||||||
type=openapi.TYPE_FILE,
|
"clear": BooleanField(default=False),
|
||||||
required=True,
|
},
|
||||||
)
|
)
|
||||||
],
|
},
|
||||||
responses={200: "Success", 400: "Bad request"},
|
responses={
|
||||||
|
200: OpenApiResponse(description="Success"),
|
||||||
|
400: OpenApiResponse(description="Bad request"),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
@action(
|
@action(
|
||||||
detail=True,
|
detail=True,
|
||||||
@ -175,16 +204,46 @@ class ApplicationViewSet(ModelViewSet):
|
|||||||
"""Set application icon"""
|
"""Set application icon"""
|
||||||
app: Application = self.get_object()
|
app: Application = self.get_object()
|
||||||
icon = request.FILES.get("file", None)
|
icon = request.FILES.get("file", None)
|
||||||
if not icon:
|
clear = request.data.get("clear", "false").lower() == "true"
|
||||||
return HttpResponseBadRequest()
|
if clear:
|
||||||
|
# .delete() saves the model by default
|
||||||
|
app.meta_icon.delete()
|
||||||
|
return Response({})
|
||||||
|
if icon:
|
||||||
app.meta_icon = icon
|
app.meta_icon = icon
|
||||||
app.save()
|
app.save()
|
||||||
return Response({})
|
return Response({})
|
||||||
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
|
@permission_required("authentik_core.change_application")
|
||||||
|
@extend_schema(
|
||||||
|
request=inline_serializer("SetIconURL", fields={"url": CharField()}),
|
||||||
|
responses={
|
||||||
|
200: OpenApiResponse(description="Success"),
|
||||||
|
400: OpenApiResponse(description="Bad request"),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
@action(
|
||||||
|
detail=True,
|
||||||
|
pagination_class=None,
|
||||||
|
filter_backends=[],
|
||||||
|
methods=["POST"],
|
||||||
|
)
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def set_icon_url(self, request: Request, slug: str):
|
||||||
|
"""Set application icon (as URL)"""
|
||||||
|
app: Application = self.get_object()
|
||||||
|
url = request.data.get("url", None)
|
||||||
|
if url is None:
|
||||||
|
return HttpResponseBadRequest()
|
||||||
|
app.meta_icon.name = url
|
||||||
|
app.save()
|
||||||
|
return Response({})
|
||||||
|
|
||||||
@permission_required(
|
@permission_required(
|
||||||
"authentik_core.view_application", ["authentik_events.view_event"]
|
"authentik_core.view_application", ["authentik_events.view_event"]
|
||||||
)
|
)
|
||||||
@swagger_auto_schema(responses={200: CoordinateSerializer(many=True)})
|
@extend_schema(responses={200: CoordinateSerializer(many=True)})
|
||||||
@action(detail=True, pagination_class=None, filter_backends=[])
|
@action(detail=True, pagination_class=None, filter_backends=[])
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def metrics(self, request: Request, slug: str):
|
def metrics(self, request: Request, slug: str):
|
||||||
|
117
authentik/core/api/authenticated_sessions.py
Normal file
117
authentik/core/api/authenticated_sessions.py
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
"""AuthenticatedSessions API Viewset"""
|
||||||
|
from typing import Optional, TypedDict
|
||||||
|
|
||||||
|
from django_filters.rest_framework import DjangoFilterBackend
|
||||||
|
from guardian.utils import get_anonymous_user
|
||||||
|
from rest_framework import mixins
|
||||||
|
from rest_framework.fields import SerializerMethodField
|
||||||
|
from rest_framework.filters import OrderingFilter, SearchFilter
|
||||||
|
from rest_framework.request import Request
|
||||||
|
from rest_framework.serializers import ModelSerializer
|
||||||
|
from rest_framework.viewsets import GenericViewSet
|
||||||
|
from ua_parser import user_agent_parser
|
||||||
|
|
||||||
|
from authentik.core.api.used_by import UsedByMixin
|
||||||
|
from authentik.core.models import AuthenticatedSession
|
||||||
|
from authentik.events.geo import GEOIP_READER, GeoIPDict
|
||||||
|
|
||||||
|
|
||||||
|
class UserAgentDeviceDict(TypedDict):
|
||||||
|
"""User agent device"""
|
||||||
|
|
||||||
|
brand: str
|
||||||
|
family: str
|
||||||
|
model: str
|
||||||
|
|
||||||
|
|
||||||
|
class UserAgentOSDict(TypedDict):
|
||||||
|
"""User agent os"""
|
||||||
|
|
||||||
|
family: str
|
||||||
|
major: str
|
||||||
|
minor: str
|
||||||
|
patch: str
|
||||||
|
patch_minor: str
|
||||||
|
|
||||||
|
|
||||||
|
class UserAgentBrowserDict(TypedDict):
|
||||||
|
"""User agent browser"""
|
||||||
|
|
||||||
|
family: str
|
||||||
|
major: str
|
||||||
|
minor: str
|
||||||
|
patch: str
|
||||||
|
|
||||||
|
|
||||||
|
class UserAgentDict(TypedDict):
|
||||||
|
"""User agent details"""
|
||||||
|
|
||||||
|
device: UserAgentDeviceDict
|
||||||
|
os: UserAgentOSDict
|
||||||
|
user_agent: UserAgentBrowserDict
|
||||||
|
string: str
|
||||||
|
|
||||||
|
|
||||||
|
class AuthenticatedSessionSerializer(ModelSerializer):
|
||||||
|
"""AuthenticatedSession Serializer"""
|
||||||
|
|
||||||
|
current = SerializerMethodField()
|
||||||
|
user_agent = SerializerMethodField()
|
||||||
|
geo_ip = SerializerMethodField()
|
||||||
|
|
||||||
|
def get_current(self, instance: AuthenticatedSession) -> bool:
|
||||||
|
"""Check if session is currently active session"""
|
||||||
|
request: Request = self.context["request"]
|
||||||
|
return request._request.session.session_key == instance.session_key
|
||||||
|
|
||||||
|
def get_user_agent(self, instance: AuthenticatedSession) -> UserAgentDict:
|
||||||
|
"""Get parsed user agent"""
|
||||||
|
return user_agent_parser.Parse(instance.last_user_agent)
|
||||||
|
|
||||||
|
def get_geo_ip(
|
||||||
|
self, instance: AuthenticatedSession
|
||||||
|
) -> Optional[GeoIPDict]: # pragma: no cover
|
||||||
|
"""Get parsed user agent"""
|
||||||
|
return GEOIP_READER.city_dict(instance.last_ip)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
|
||||||
|
model = AuthenticatedSession
|
||||||
|
fields = [
|
||||||
|
"uuid",
|
||||||
|
"current",
|
||||||
|
"user_agent",
|
||||||
|
"geo_ip",
|
||||||
|
"user",
|
||||||
|
"last_ip",
|
||||||
|
"last_user_agent",
|
||||||
|
"last_used",
|
||||||
|
"expires",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class AuthenticatedSessionViewSet(
|
||||||
|
mixins.RetrieveModelMixin,
|
||||||
|
mixins.DestroyModelMixin,
|
||||||
|
UsedByMixin,
|
||||||
|
mixins.ListModelMixin,
|
||||||
|
GenericViewSet,
|
||||||
|
):
|
||||||
|
"""AuthenticatedSession Viewset"""
|
||||||
|
|
||||||
|
queryset = AuthenticatedSession.objects.all()
|
||||||
|
serializer_class = AuthenticatedSessionSerializer
|
||||||
|
search_fields = ["user__username", "last_ip", "last_user_agent"]
|
||||||
|
filterset_fields = ["user__username", "last_ip", "last_user_agent"]
|
||||||
|
ordering = ["user__username"]
|
||||||
|
filter_backends = [
|
||||||
|
DjangoFilterBackend,
|
||||||
|
OrderingFilter,
|
||||||
|
SearchFilter,
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
user = self.request.user if self.request else get_anonymous_user()
|
||||||
|
if user.is_superuser:
|
||||||
|
return super().get_queryset()
|
||||||
|
return super().get_queryset().filter(user=user.pk)
|
@ -1,32 +1,90 @@
|
|||||||
"""Groups API Viewset"""
|
"""Groups API Viewset"""
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
from rest_framework.fields import JSONField
|
from django_filters.filters import ModelMultipleChoiceFilter
|
||||||
from rest_framework.serializers import ModelSerializer
|
from django_filters.filterset import FilterSet
|
||||||
|
from rest_framework.fields import BooleanField, CharField, JSONField
|
||||||
|
from rest_framework.serializers import ListSerializer, ModelSerializer
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
from rest_framework_guardian.filters import ObjectPermissionsFilter
|
from rest_framework_guardian.filters import ObjectPermissionsFilter
|
||||||
|
|
||||||
|
from authentik.core.api.used_by import UsedByMixin
|
||||||
from authentik.core.api.utils import is_dict
|
from authentik.core.api.utils import is_dict
|
||||||
from authentik.core.models import Group
|
from authentik.core.models import Group, User
|
||||||
|
|
||||||
|
|
||||||
|
class GroupMemberSerializer(ModelSerializer):
|
||||||
|
"""Stripped down user serializer to show relevant users for groups"""
|
||||||
|
|
||||||
|
is_superuser = BooleanField(read_only=True)
|
||||||
|
avatar = CharField(read_only=True)
|
||||||
|
attributes = JSONField(validators=[is_dict], required=False)
|
||||||
|
uid = CharField(read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
|
||||||
|
model = User
|
||||||
|
fields = [
|
||||||
|
"pk",
|
||||||
|
"username",
|
||||||
|
"name",
|
||||||
|
"is_active",
|
||||||
|
"last_login",
|
||||||
|
"is_superuser",
|
||||||
|
"email",
|
||||||
|
"avatar",
|
||||||
|
"attributes",
|
||||||
|
"uid",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class GroupSerializer(ModelSerializer):
|
class GroupSerializer(ModelSerializer):
|
||||||
"""Group Serializer"""
|
"""Group Serializer"""
|
||||||
|
|
||||||
attributes = JSONField(validators=[is_dict], required=False)
|
attributes = JSONField(validators=[is_dict], required=False)
|
||||||
|
users_obj = ListSerializer(
|
||||||
|
child=GroupMemberSerializer(), read_only=True, source="users", required=False
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
||||||
model = Group
|
model = Group
|
||||||
fields = ["pk", "name", "is_superuser", "parent", "users", "attributes"]
|
fields = [
|
||||||
|
"pk",
|
||||||
|
"name",
|
||||||
|
"is_superuser",
|
||||||
|
"parent",
|
||||||
|
"users",
|
||||||
|
"attributes",
|
||||||
|
"users_obj",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class GroupViewSet(ModelViewSet):
|
class GroupFilter(FilterSet):
|
||||||
|
"""Filter for groups"""
|
||||||
|
|
||||||
|
members_by_username = ModelMultipleChoiceFilter(
|
||||||
|
field_name="users__username",
|
||||||
|
to_field_name="username",
|
||||||
|
queryset=User.objects.all(),
|
||||||
|
)
|
||||||
|
members_by_pk = ModelMultipleChoiceFilter(
|
||||||
|
field_name="users",
|
||||||
|
queryset=User.objects.all(),
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
|
||||||
|
model = Group
|
||||||
|
fields = ["name", "is_superuser", "members_by_pk", "members_by_username"]
|
||||||
|
|
||||||
|
|
||||||
|
class GroupViewSet(UsedByMixin, ModelViewSet):
|
||||||
"""Group Viewset"""
|
"""Group Viewset"""
|
||||||
|
|
||||||
queryset = Group.objects.all()
|
queryset = Group.objects.all()
|
||||||
serializer_class = GroupSerializer
|
serializer_class = GroupSerializer
|
||||||
search_fields = ["name", "is_superuser"]
|
search_fields = ["name", "is_superuser"]
|
||||||
filterset_fields = ["name", "is_superuser"]
|
filterset_class = GroupFilter
|
||||||
ordering = ["name"]
|
ordering = ["name"]
|
||||||
|
|
||||||
def _filter_queryset_for_list(self, queryset: QuerySet) -> QuerySet:
|
def _filter_queryset_for_list(self, queryset: QuerySet) -> QuerySet:
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
"""PropertyMapping API Views"""
|
"""PropertyMapping API Views"""
|
||||||
from json import dumps
|
from json import dumps
|
||||||
|
|
||||||
from drf_yasg import openapi
|
from drf_spectacular.types import OpenApiTypes
|
||||||
from drf_yasg.utils import swagger_auto_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 import mixins
|
from rest_framework import mixins
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
@ -14,6 +14,7 @@ from rest_framework.serializers import ModelSerializer, SerializerMethodField
|
|||||||
from rest_framework.viewsets import GenericViewSet
|
from rest_framework.viewsets import GenericViewSet
|
||||||
|
|
||||||
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.utils import (
|
from authentik.core.api.utils import (
|
||||||
MetaNameSerializer,
|
MetaNameSerializer,
|
||||||
PassiveSerializer,
|
PassiveSerializer,
|
||||||
@ -65,6 +66,7 @@ class PropertyMappingSerializer(ManagedSerializer, ModelSerializer, MetaNameSeri
|
|||||||
class PropertyMappingViewSet(
|
class PropertyMappingViewSet(
|
||||||
mixins.RetrieveModelMixin,
|
mixins.RetrieveModelMixin,
|
||||||
mixins.DestroyModelMixin,
|
mixins.DestroyModelMixin,
|
||||||
|
UsedByMixin,
|
||||||
mixins.ListModelMixin,
|
mixins.ListModelMixin,
|
||||||
GenericViewSet,
|
GenericViewSet,
|
||||||
):
|
):
|
||||||
@ -78,10 +80,10 @@ class PropertyMappingViewSet(
|
|||||||
filterset_fields = {"managed": ["isnull"]}
|
filterset_fields = {"managed": ["isnull"]}
|
||||||
ordering = ["name"]
|
ordering = ["name"]
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self): # pragma: no cover
|
||||||
return PropertyMapping.objects.select_subclasses()
|
return PropertyMapping.objects.select_subclasses()
|
||||||
|
|
||||||
@swagger_auto_schema(responses={200: TypeCreateSerializer(many=True)})
|
@extend_schema(responses={200: TypeCreateSerializer(many=True)})
|
||||||
@action(detail=False, pagination_class=None, filter_backends=[])
|
@action(detail=False, pagination_class=None, filter_backends=[])
|
||||||
def types(self, request: Request) -> Response:
|
def types(self, request: Request) -> Response:
|
||||||
"""Get all creatable property-mapping types"""
|
"""Get all creatable property-mapping types"""
|
||||||
@ -100,14 +102,17 @@ class PropertyMappingViewSet(
|
|||||||
return Response(TypeCreateSerializer(data, many=True).data)
|
return Response(TypeCreateSerializer(data, many=True).data)
|
||||||
|
|
||||||
@permission_required("authentik_core.view_propertymapping")
|
@permission_required("authentik_core.view_propertymapping")
|
||||||
@swagger_auto_schema(
|
@extend_schema(
|
||||||
request_body=PolicyTestSerializer(),
|
request=PolicyTestSerializer(),
|
||||||
responses={200: PropertyMappingTestResultSerializer, 400: "Invalid parameters"},
|
responses={
|
||||||
manual_parameters=[
|
200: PropertyMappingTestResultSerializer,
|
||||||
openapi.Parameter(
|
400: OpenApiResponse(description="Invalid parameters"),
|
||||||
|
},
|
||||||
|
parameters=[
|
||||||
|
OpenApiParameter(
|
||||||
name="format_result",
|
name="format_result",
|
||||||
in_=openapi.IN_QUERY,
|
location=OpenApiParameter.QUERY,
|
||||||
type=openapi.TYPE_BOOLEAN,
|
type=OpenApiTypes.BOOL,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Provider API Views"""
|
"""Provider API Views"""
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from drf_yasg.utils import swagger_auto_schema
|
from drf_spectacular.utils import extend_schema
|
||||||
from rest_framework import mixins
|
from rest_framework import mixins
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.fields import ReadOnlyField
|
from rest_framework.fields import ReadOnlyField
|
||||||
@ -9,6 +9,7 @@ from rest_framework.response import Response
|
|||||||
from rest_framework.serializers import ModelSerializer, SerializerMethodField
|
from rest_framework.serializers import ModelSerializer, SerializerMethodField
|
||||||
from rest_framework.viewsets import GenericViewSet
|
from rest_framework.viewsets import GenericViewSet
|
||||||
|
|
||||||
|
from authentik.core.api.used_by import UsedByMixin
|
||||||
from authentik.core.api.utils import MetaNameSerializer, TypeCreateSerializer
|
from authentik.core.api.utils import MetaNameSerializer, TypeCreateSerializer
|
||||||
from authentik.core.models import Provider
|
from authentik.core.models import Provider
|
||||||
from authentik.lib.utils.reflection import all_subclasses
|
from authentik.lib.utils.reflection import all_subclasses
|
||||||
@ -22,7 +23,7 @@ class ProviderSerializer(ModelSerializer, MetaNameSerializer):
|
|||||||
|
|
||||||
component = SerializerMethodField()
|
component = SerializerMethodField()
|
||||||
|
|
||||||
def get_component(self, obj: Provider): # pragma: no cover
|
def get_component(self, obj: Provider) -> str: # pragma: no cover
|
||||||
"""Get object component so that we know how to edit the object"""
|
"""Get object component so that we know how to edit the object"""
|
||||||
# pyright: reportGeneralTypeIssues=false
|
# pyright: reportGeneralTypeIssues=false
|
||||||
if obj.__class__ == Provider:
|
if obj.__class__ == Provider:
|
||||||
@ -48,6 +49,7 @@ class ProviderSerializer(ModelSerializer, MetaNameSerializer):
|
|||||||
class ProviderViewSet(
|
class ProviderViewSet(
|
||||||
mixins.RetrieveModelMixin,
|
mixins.RetrieveModelMixin,
|
||||||
mixins.DestroyModelMixin,
|
mixins.DestroyModelMixin,
|
||||||
|
UsedByMixin,
|
||||||
mixins.ListModelMixin,
|
mixins.ListModelMixin,
|
||||||
GenericViewSet,
|
GenericViewSet,
|
||||||
):
|
):
|
||||||
@ -63,10 +65,10 @@ class ProviderViewSet(
|
|||||||
"application__name",
|
"application__name",
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self): # pragma: no cover
|
||||||
return Provider.objects.select_subclasses()
|
return Provider.objects.select_subclasses()
|
||||||
|
|
||||||
@swagger_auto_schema(responses={200: TypeCreateSerializer(many=True)})
|
@extend_schema(responses={200: TypeCreateSerializer(many=True)})
|
||||||
@action(detail=False, pagination_class=None, filter_backends=[])
|
@action(detail=False, pagination_class=None, filter_backends=[])
|
||||||
def types(self, request: Request) -> Response:
|
def types(self, request: Request) -> Response:
|
||||||
"""Get all creatable provider types"""
|
"""Get all creatable provider types"""
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""Source API Views"""
|
"""Source API Views"""
|
||||||
from typing import Iterable
|
from typing import Iterable
|
||||||
|
|
||||||
from drf_yasg.utils import swagger_auto_schema
|
from drf_spectacular.utils import extend_schema
|
||||||
from rest_framework import mixins
|
from rest_framework import mixins
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
@ -10,6 +10,7 @@ from rest_framework.serializers import ModelSerializer, SerializerMethodField
|
|||||||
from rest_framework.viewsets import GenericViewSet
|
from rest_framework.viewsets import GenericViewSet
|
||||||
from structlog.stdlib import get_logger
|
from structlog.stdlib import get_logger
|
||||||
|
|
||||||
|
from authentik.core.api.used_by import UsedByMixin
|
||||||
from authentik.core.api.utils import MetaNameSerializer, TypeCreateSerializer
|
from authentik.core.api.utils import MetaNameSerializer, TypeCreateSerializer
|
||||||
from authentik.core.models import Source
|
from authentik.core.models import Source
|
||||||
from authentik.core.types import UserSettingSerializer
|
from authentik.core.types import UserSettingSerializer
|
||||||
@ -24,7 +25,7 @@ class SourceSerializer(ModelSerializer, MetaNameSerializer):
|
|||||||
|
|
||||||
component = SerializerMethodField()
|
component = SerializerMethodField()
|
||||||
|
|
||||||
def get_component(self, obj: Source):
|
def get_component(self, obj: Source) -> str:
|
||||||
"""Get object component so that we know how to edit the object"""
|
"""Get object component so that we know how to edit the object"""
|
||||||
# pyright: reportGeneralTypeIssues=false
|
# pyright: reportGeneralTypeIssues=false
|
||||||
if obj.__class__ == Source:
|
if obj.__class__ == Source:
|
||||||
@ -52,6 +53,7 @@ class SourceSerializer(ModelSerializer, MetaNameSerializer):
|
|||||||
class SourceViewSet(
|
class SourceViewSet(
|
||||||
mixins.RetrieveModelMixin,
|
mixins.RetrieveModelMixin,
|
||||||
mixins.DestroyModelMixin,
|
mixins.DestroyModelMixin,
|
||||||
|
UsedByMixin,
|
||||||
mixins.ListModelMixin,
|
mixins.ListModelMixin,
|
||||||
GenericViewSet,
|
GenericViewSet,
|
||||||
):
|
):
|
||||||
@ -61,10 +63,10 @@ class SourceViewSet(
|
|||||||
serializer_class = SourceSerializer
|
serializer_class = SourceSerializer
|
||||||
lookup_field = "slug"
|
lookup_field = "slug"
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self): # pragma: no cover
|
||||||
return Source.objects.select_subclasses()
|
return Source.objects.select_subclasses()
|
||||||
|
|
||||||
@swagger_auto_schema(responses={200: TypeCreateSerializer(many=True)})
|
@extend_schema(responses={200: TypeCreateSerializer(many=True)})
|
||||||
@action(detail=False, pagination_class=None, filter_backends=[])
|
@action(detail=False, pagination_class=None, filter_backends=[])
|
||||||
def types(self, request: Request) -> Response:
|
def types(self, request: Request) -> Response:
|
||||||
"""Get all creatable source types"""
|
"""Get all creatable source types"""
|
||||||
@ -87,7 +89,7 @@ class SourceViewSet(
|
|||||||
)
|
)
|
||||||
return Response(TypeCreateSerializer(data, many=True).data)
|
return Response(TypeCreateSerializer(data, many=True).data)
|
||||||
|
|
||||||
@swagger_auto_schema(responses={200: UserSettingSerializer(many=True)})
|
@extend_schema(responses={200: UserSettingSerializer(many=True)})
|
||||||
@action(detail=False, pagination_class=None, filter_backends=[])
|
@action(detail=False, pagination_class=None, filter_backends=[])
|
||||||
def user_settings(self, request: Request) -> Response:
|
def user_settings(self, request: Request) -> Response:
|
||||||
"""Get all sources the user can configure"""
|
"""Get all sources the user can configure"""
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Tokens API Viewset"""
|
"""Tokens API Viewset"""
|
||||||
from django.http.response import Http404
|
from django.http.response import Http404
|
||||||
from drf_yasg.utils import swagger_auto_schema
|
from drf_spectacular.utils import OpenApiResponse, extend_schema
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.fields import CharField
|
from rest_framework.fields import CharField
|
||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
@ -9,9 +9,10 @@ from rest_framework.serializers import ModelSerializer
|
|||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
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.users import UserSerializer
|
from authentik.core.api.users import UserSerializer
|
||||||
from authentik.core.api.utils import PassiveSerializer
|
from authentik.core.api.utils import PassiveSerializer
|
||||||
from authentik.core.models import Token, TokenIntents
|
from authentik.core.models import USER_ATTRIBUTE_TOKEN_EXPIRING, Token, TokenIntents
|
||||||
from authentik.events.models import Event, EventAction
|
from authentik.events.models import Event, EventAction
|
||||||
from authentik.managed.api import ManagedSerializer
|
from authentik.managed.api import ManagedSerializer
|
||||||
|
|
||||||
@ -43,11 +44,11 @@ class TokenViewSerializer(PassiveSerializer):
|
|||||||
key = CharField(read_only=True)
|
key = CharField(read_only=True)
|
||||||
|
|
||||||
|
|
||||||
class TokenViewSet(ModelViewSet):
|
class TokenViewSet(UsedByMixin, ModelViewSet):
|
||||||
"""Token Viewset"""
|
"""Token Viewset"""
|
||||||
|
|
||||||
lookup_field = "identifier"
|
lookup_field = "identifier"
|
||||||
queryset = Token.filter_not_expired()
|
queryset = Token.objects.all()
|
||||||
serializer_class = TokenSerializer
|
serializer_class = TokenSerializer
|
||||||
search_fields = [
|
search_fields = [
|
||||||
"identifier",
|
"identifier",
|
||||||
@ -60,17 +61,25 @@ class TokenViewSet(ModelViewSet):
|
|||||||
"intent",
|
"intent",
|
||||||
"user__username",
|
"user__username",
|
||||||
"description",
|
"description",
|
||||||
|
"expires",
|
||||||
|
"expiring",
|
||||||
]
|
]
|
||||||
ordering = ["expires"]
|
ordering = ["expires"]
|
||||||
|
|
||||||
def perform_create(self, serializer: TokenSerializer):
|
def perform_create(self, serializer: TokenSerializer):
|
||||||
serializer.save(user=self.request.user, intent=TokenIntents.INTENT_API)
|
serializer.save(
|
||||||
|
user=self.request.user,
|
||||||
|
intent=TokenIntents.INTENT_API,
|
||||||
|
expiring=self.request.user.attributes.get(
|
||||||
|
USER_ATTRIBUTE_TOKEN_EXPIRING, True
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
@permission_required("authentik_core.view_token_key")
|
@permission_required("authentik_core.view_token_key")
|
||||||
@swagger_auto_schema(
|
@extend_schema(
|
||||||
responses={
|
responses={
|
||||||
200: TokenViewSerializer(many=False),
|
200: TokenViewSerializer(many=False),
|
||||||
404: "Token not found or expired",
|
404: OpenApiResponse(description="Token not found or expired"),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@action(detail=True, pagination_class=None, filter_backends=[])
|
@action(detail=True, pagination_class=None, filter_backends=[])
|
||||||
|
102
authentik/core/api/used_by.py
Normal file
102
authentik/core/api/used_by.py
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
"""used_by mixin"""
|
||||||
|
from enum import Enum
|
||||||
|
from inspect import getmembers
|
||||||
|
|
||||||
|
from django.db.models.base import Model
|
||||||
|
from django.db.models.deletion import SET_DEFAULT, SET_NULL
|
||||||
|
from django.db.models.manager import Manager
|
||||||
|
from drf_spectacular.utils import extend_schema
|
||||||
|
from guardian.shortcuts import get_objects_for_user
|
||||||
|
from rest_framework.decorators import action
|
||||||
|
from rest_framework.fields import CharField, ChoiceField
|
||||||
|
from rest_framework.request import Request
|
||||||
|
from rest_framework.response import Response
|
||||||
|
|
||||||
|
from authentik.core.api.utils import PassiveSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class DeleteAction(Enum):
|
||||||
|
"""Which action a delete will have on a used object"""
|
||||||
|
|
||||||
|
CASCADE = "cascade"
|
||||||
|
CASCADE_MANY = "cascade_many"
|
||||||
|
SET_NULL = "set_null"
|
||||||
|
SET_DEFAULT = "set_default"
|
||||||
|
|
||||||
|
|
||||||
|
class UsedBySerializer(PassiveSerializer):
|
||||||
|
"""A list of all objects referencing the queried object"""
|
||||||
|
|
||||||
|
app = CharField()
|
||||||
|
model_name = CharField()
|
||||||
|
pk = CharField()
|
||||||
|
name = CharField()
|
||||||
|
action = ChoiceField(choices=[(x.name, x.name) for x in DeleteAction])
|
||||||
|
|
||||||
|
|
||||||
|
def get_delete_action(manager: Manager) -> str:
|
||||||
|
"""Get the delete action from the Foreign key, falls back to cascade"""
|
||||||
|
if hasattr(manager, "field"):
|
||||||
|
if manager.field.remote_field.on_delete.__name__ == SET_NULL.__name__:
|
||||||
|
return DeleteAction.SET_NULL.name
|
||||||
|
if manager.field.remote_field.on_delete.__name__ == SET_DEFAULT.__name__:
|
||||||
|
return DeleteAction.SET_DEFAULT.name
|
||||||
|
if hasattr(manager, "source_field"):
|
||||||
|
return DeleteAction.CASCADE_MANY.name
|
||||||
|
return DeleteAction.CASCADE.name
|
||||||
|
|
||||||
|
|
||||||
|
class UsedByMixin:
|
||||||
|
"""Mixin to add a used_by endpoint to return a list of all objects using this object"""
|
||||||
|
|
||||||
|
@extend_schema(
|
||||||
|
responses={200: UsedBySerializer(many=True)},
|
||||||
|
)
|
||||||
|
@action(detail=True, pagination_class=None, filter_backends=[])
|
||||||
|
# pylint: disable=invalid-name, unused-argument, too-many-locals
|
||||||
|
def used_by(self, request: Request, *args, **kwargs) -> Response:
|
||||||
|
"""Get a list of all objects that use this object"""
|
||||||
|
# pyright: reportGeneralTypeIssues=false
|
||||||
|
model: Model = self.get_object()
|
||||||
|
used_by = []
|
||||||
|
shadows = []
|
||||||
|
for attr_name, manager in getmembers(model, lambda x: isinstance(x, Manager)):
|
||||||
|
if attr_name == "objects": # pragma: no cover
|
||||||
|
continue
|
||||||
|
manager: Manager
|
||||||
|
if manager.model._meta.abstract:
|
||||||
|
continue
|
||||||
|
app = manager.model._meta.app_label
|
||||||
|
model_name = manager.model._meta.model_name
|
||||||
|
delete_action = get_delete_action(manager)
|
||||||
|
|
||||||
|
# To make sure we only apply shadows when there are any objects,
|
||||||
|
# but so we only apply them once, have a simple flag for the first object
|
||||||
|
first_object = True
|
||||||
|
|
||||||
|
for obj in get_objects_for_user(
|
||||||
|
request.user, f"{app}.view_{model_name}", manager
|
||||||
|
).all():
|
||||||
|
# Only merge shadows on first object
|
||||||
|
if first_object:
|
||||||
|
shadows += getattr(
|
||||||
|
manager.model._meta, "authentik_used_by_shadows", []
|
||||||
|
)
|
||||||
|
first_object = False
|
||||||
|
serializer = UsedBySerializer(
|
||||||
|
data={
|
||||||
|
"app": app,
|
||||||
|
"model_name": model_name,
|
||||||
|
"pk": str(obj.pk),
|
||||||
|
"name": str(obj),
|
||||||
|
"action": delete_action,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
serializer.is_valid()
|
||||||
|
used_by.append(serializer.data)
|
||||||
|
# Check the shadows map and remove anything that should be shadowed
|
||||||
|
for idx, user in enumerate(used_by):
|
||||||
|
full_model_name = f"{user['app']}.{user['model_name']}"
|
||||||
|
if full_model_name in shadows:
|
||||||
|
del used_by[idx]
|
||||||
|
return Response(used_by)
|
@ -2,15 +2,15 @@
|
|||||||
from json import loads
|
from json import loads
|
||||||
|
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
from django.http.response import Http404
|
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.utils.http import urlencode
|
from django.utils.http import urlencode
|
||||||
from django_filters.filters import BooleanFilter, CharFilter
|
from django_filters.filters import BooleanFilter, CharFilter
|
||||||
from django_filters.filterset import FilterSet
|
from django_filters.filterset import FilterSet
|
||||||
from drf_yasg.utils import swagger_auto_schema, swagger_serializer_method
|
from drf_spectacular.utils import extend_schema, extend_schema_field
|
||||||
from guardian.utils import get_anonymous_user
|
from guardian.utils import get_anonymous_user
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.fields import CharField, JSONField, SerializerMethodField
|
from rest_framework.fields import CharField, 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 (
|
||||||
@ -25,6 +25,7 @@ from rest_framework_guardian.filters import ObjectPermissionsFilter
|
|||||||
from authentik.admin.api.metrics import CoordinateSerializer, get_events_per_1h
|
from authentik.admin.api.metrics import CoordinateSerializer, get_events_per_1h
|
||||||
from authentik.api.decorators import permission_required
|
from authentik.api.decorators import permission_required
|
||||||
from authentik.core.api.groups import GroupSerializer
|
from authentik.core.api.groups import GroupSerializer
|
||||||
|
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 (
|
from authentik.core.middleware import (
|
||||||
SESSION_IMPERSONATE_ORIGINAL_USER,
|
SESSION_IMPERSONATE_ORIGINAL_USER,
|
||||||
@ -32,7 +33,7 @@ from authentik.core.middleware import (
|
|||||||
)
|
)
|
||||||
from authentik.core.models import Token, TokenIntents, User
|
from authentik.core.models import Token, TokenIntents, User
|
||||||
from authentik.events.models import EventAction
|
from authentik.events.models import EventAction
|
||||||
from authentik.flows.models import Flow, FlowDesignation
|
from authentik.tenants.models import Tenant
|
||||||
|
|
||||||
|
|
||||||
class UserSerializer(ModelSerializer):
|
class UserSerializer(ModelSerializer):
|
||||||
@ -62,12 +63,40 @@ class UserSerializer(ModelSerializer):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class UserSelfSerializer(ModelSerializer):
|
||||||
|
"""User Serializer for information a user can retrieve about themselves and
|
||||||
|
update about themselves"""
|
||||||
|
|
||||||
|
is_superuser = BooleanField(read_only=True)
|
||||||
|
avatar = CharField(read_only=True)
|
||||||
|
groups = ListSerializer(child=GroupSerializer(), read_only=True, source="ak_groups")
|
||||||
|
uid = CharField(read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
|
||||||
|
model = User
|
||||||
|
fields = [
|
||||||
|
"pk",
|
||||||
|
"username",
|
||||||
|
"name",
|
||||||
|
"is_active",
|
||||||
|
"is_superuser",
|
||||||
|
"groups",
|
||||||
|
"email",
|
||||||
|
"avatar",
|
||||||
|
"uid",
|
||||||
|
]
|
||||||
|
extra_kwargs = {
|
||||||
|
"is_active": {"read_only": True},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class SessionUserSerializer(PassiveSerializer):
|
class SessionUserSerializer(PassiveSerializer):
|
||||||
"""Response for the /user/me endpoint, returns the currently active user (as `user` property)
|
"""Response for the /user/me endpoint, returns the currently active user (as `user` property)
|
||||||
and, if this user is being impersonated, the original user in the `original` property."""
|
and, if this user is being impersonated, the original user in the `original` property."""
|
||||||
|
|
||||||
user = UserSerializer()
|
user = UserSelfSerializer()
|
||||||
original = UserSerializer(required=False)
|
original = UserSelfSerializer(required=False)
|
||||||
|
|
||||||
|
|
||||||
class UserMetricsSerializer(PassiveSerializer):
|
class UserMetricsSerializer(PassiveSerializer):
|
||||||
@ -77,13 +106,13 @@ class UserMetricsSerializer(PassiveSerializer):
|
|||||||
logins_failed_per_1h = SerializerMethodField()
|
logins_failed_per_1h = SerializerMethodField()
|
||||||
authorizations_per_1h = SerializerMethodField()
|
authorizations_per_1h = SerializerMethodField()
|
||||||
|
|
||||||
@swagger_serializer_method(serializer_or_field=CoordinateSerializer(many=True))
|
@extend_schema_field(CoordinateSerializer(many=True))
|
||||||
def get_logins_per_1h(self, _):
|
def get_logins_per_1h(self, _):
|
||||||
"""Get successful logins per hour for the last 24 hours"""
|
"""Get successful logins per hour for the last 24 hours"""
|
||||||
user = self.context["user"]
|
user = self.context["user"]
|
||||||
return get_events_per_1h(action=EventAction.LOGIN, user__pk=user.pk)
|
return get_events_per_1h(action=EventAction.LOGIN, user__pk=user.pk)
|
||||||
|
|
||||||
@swagger_serializer_method(serializer_or_field=CoordinateSerializer(many=True))
|
@extend_schema_field(CoordinateSerializer(many=True))
|
||||||
def get_logins_failed_per_1h(self, _):
|
def get_logins_failed_per_1h(self, _):
|
||||||
"""Get failed logins per hour for the last 24 hours"""
|
"""Get failed logins per hour for the last 24 hours"""
|
||||||
user = self.context["user"]
|
user = self.context["user"]
|
||||||
@ -91,7 +120,7 @@ class UserMetricsSerializer(PassiveSerializer):
|
|||||||
action=EventAction.LOGIN_FAILED, context__username=user.username
|
action=EventAction.LOGIN_FAILED, context__username=user.username
|
||||||
)
|
)
|
||||||
|
|
||||||
@swagger_serializer_method(serializer_or_field=CoordinateSerializer(many=True))
|
@extend_schema_field(CoordinateSerializer(many=True))
|
||||||
def get_authorizations_per_1h(self, _):
|
def get_authorizations_per_1h(self, _):
|
||||||
"""Get failed logins per hour for the last 24 hours"""
|
"""Get failed logins per hour for the last 24 hours"""
|
||||||
user = self.context["user"]
|
user = self.context["user"]
|
||||||
@ -128,21 +157,28 @@ class UsersFilter(FilterSet):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
fields = ["username", "name", "is_active", "is_superuser", "attributes"]
|
fields = [
|
||||||
|
"username",
|
||||||
|
"email",
|
||||||
|
"name",
|
||||||
|
"is_active",
|
||||||
|
"is_superuser",
|
||||||
|
"attributes",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class UserViewSet(ModelViewSet):
|
class UserViewSet(UsedByMixin, ModelViewSet):
|
||||||
"""User Viewset"""
|
"""User Viewset"""
|
||||||
|
|
||||||
queryset = User.objects.none()
|
queryset = User.objects.none()
|
||||||
serializer_class = UserSerializer
|
serializer_class = UserSerializer
|
||||||
search_fields = ["username", "name", "is_active"]
|
search_fields = ["username", "name", "is_active", "email"]
|
||||||
filterset_class = UsersFilter
|
filterset_class = UsersFilter
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self): # pragma: no cover
|
||||||
return User.objects.all().exclude(pk=get_anonymous_user().pk)
|
return User.objects.all().exclude(pk=get_anonymous_user().pk)
|
||||||
|
|
||||||
@swagger_auto_schema(responses={200: SessionUserSerializer(many=False)})
|
@extend_schema(responses={200: SessionUserSerializer(many=False)})
|
||||||
@action(detail=False, pagination_class=None, filter_backends=[])
|
@action(detail=False, pagination_class=None, filter_backends=[])
|
||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
def me(self, request: Request) -> Response:
|
def me(self, request: Request) -> Response:
|
||||||
@ -151,14 +187,38 @@ class UserViewSet(ModelViewSet):
|
|||||||
data={"user": UserSerializer(request.user).data}
|
data={"user": UserSerializer(request.user).data}
|
||||||
)
|
)
|
||||||
if SESSION_IMPERSONATE_USER in request._request.session:
|
if SESSION_IMPERSONATE_USER in request._request.session:
|
||||||
serializer.initial_data["original"] = UserSerializer(
|
serializer.initial_data["original"] = UserSelfSerializer(
|
||||||
request._request.session[SESSION_IMPERSONATE_ORIGINAL_USER]
|
request._request.session[SESSION_IMPERSONATE_ORIGINAL_USER]
|
||||||
).data
|
).data
|
||||||
serializer.is_valid()
|
serializer.is_valid()
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
|
@extend_schema(
|
||||||
|
request=UserSelfSerializer, responses={200: SessionUserSerializer(many=False)}
|
||||||
|
)
|
||||||
|
@action(
|
||||||
|
methods=["PUT"],
|
||||||
|
detail=False,
|
||||||
|
pagination_class=None,
|
||||||
|
filter_backends=[],
|
||||||
|
permission_classes=[IsAuthenticated],
|
||||||
|
)
|
||||||
|
def update_self(self, request: Request) -> Response:
|
||||||
|
"""Allow users to change information on their own profile"""
|
||||||
|
data = UserSelfSerializer(
|
||||||
|
instance=User.objects.get(pk=request.user.pk), data=request.data
|
||||||
|
)
|
||||||
|
if not data.is_valid():
|
||||||
|
return Response(data.errors)
|
||||||
|
new_user = data.save()
|
||||||
|
# If we're impersonating, we need to update that user object
|
||||||
|
# since it caches the full object
|
||||||
|
if SESSION_IMPERSONATE_USER in request.session:
|
||||||
|
request.session[SESSION_IMPERSONATE_USER] = new_user
|
||||||
|
return self.me(request)
|
||||||
|
|
||||||
@permission_required("authentik_core.view_user", ["authentik_events.view_event"])
|
@permission_required("authentik_core.view_user", ["authentik_events.view_event"])
|
||||||
@swagger_auto_schema(responses={200: UserMetricsSerializer(many=False)})
|
@extend_schema(responses={200: UserMetricsSerializer(many=False)})
|
||||||
@action(detail=True, pagination_class=None, filter_backends=[])
|
@action(detail=True, pagination_class=None, filter_backends=[])
|
||||||
# pylint: disable=invalid-name, unused-argument
|
# pylint: disable=invalid-name, unused-argument
|
||||||
def metrics(self, request: Request, pk: int) -> Response:
|
def metrics(self, request: Request, pk: int) -> Response:
|
||||||
@ -169,17 +229,21 @@ class UserViewSet(ModelViewSet):
|
|||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
@permission_required("authentik_core.reset_user_password")
|
@permission_required("authentik_core.reset_user_password")
|
||||||
@swagger_auto_schema(
|
@extend_schema(
|
||||||
responses={"200": LinkSerializer(many=False), "404": "No recovery flow found."},
|
responses={
|
||||||
|
"200": LinkSerializer(many=False),
|
||||||
|
"404": LinkSerializer(many=False),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
@action(detail=True, pagination_class=None, filter_backends=[])
|
@action(detail=True, pagination_class=None, filter_backends=[])
|
||||||
# pylint: disable=invalid-name, unused-argument
|
# pylint: disable=invalid-name, unused-argument
|
||||||
def recovery(self, request: Request, pk: int) -> Response:
|
def recovery(self, request: Request, pk: int) -> Response:
|
||||||
"""Create a temporary link that a user can use to recover their accounts"""
|
"""Create a temporary link that a user can use to recover their accounts"""
|
||||||
|
tenant: Tenant = request._request.tenant
|
||||||
# Check that there is a recovery flow, if not return an error
|
# Check that there is a recovery flow, if not return an error
|
||||||
flow = Flow.with_policy(request, designation=FlowDesignation.RECOVERY)
|
flow = tenant.flow_recovery
|
||||||
if not flow:
|
if not flow:
|
||||||
raise Http404
|
return Response({"link": ""}, status=404)
|
||||||
user: User = self.get_object()
|
user: User = self.get_object()
|
||||||
token, __ = Token.objects.get_or_create(
|
token, __ = Token.objects.get_or_create(
|
||||||
identifier=f"{user.uid}-password-reset",
|
identifier=f"{user.uid}-password-reset",
|
||||||
@ -188,7 +252,8 @@ class UserViewSet(ModelViewSet):
|
|||||||
)
|
)
|
||||||
querystring = urlencode({"token": token.key})
|
querystring = urlencode({"token": token.key})
|
||||||
link = request.build_absolute_uri(
|
link = request.build_absolute_uri(
|
||||||
reverse_lazy("authentik_flows:default-recovery") + f"?{querystring}"
|
reverse_lazy("authentik_core:if-flow", kwargs={"flow_slug": flow.slug})
|
||||||
|
+ f"?{querystring}"
|
||||||
)
|
)
|
||||||
return Response({"link": link})
|
return Response({"link": link})
|
||||||
|
|
||||||
@ -201,6 +266,6 @@ class UserViewSet(ModelViewSet):
|
|||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
def filter_queryset(self, queryset):
|
def filter_queryset(self, queryset):
|
||||||
if self.request.user.has_perm("authentik_core.view_group"):
|
if self.request.user.has_perm("authentik_core.view_user"):
|
||||||
return self._filter_queryset_for_list(queryset)
|
return self._filter_queryset_for_list(queryset)
|
||||||
return super().filter_queryset(queryset)
|
return super().filter_queryset(queryset)
|
||||||
|
@ -14,7 +14,9 @@ def is_dict(value: Any):
|
|||||||
"""Ensure a value is a dictionary, useful for JSONFields"""
|
"""Ensure a value is a dictionary, useful for JSONFields"""
|
||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
return
|
return
|
||||||
raise ValidationError("Value must be a dictionary.")
|
raise ValidationError(
|
||||||
|
"Value must be a dictionary, and not have any duplicate keys."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class PassiveSerializer(Serializer):
|
class PassiveSerializer(Serializer):
|
||||||
@ -28,6 +30,9 @@ class PassiveSerializer(Serializer):
|
|||||||
) -> Model: # pragma: no cover
|
) -> Model: # pragma: no cover
|
||||||
return Model()
|
return Model()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Model
|
||||||
|
|
||||||
|
|
||||||
class MetaNameSerializer(PassiveSerializer):
|
class MetaNameSerializer(PassiveSerializer):
|
||||||
"""Add verbose names to response"""
|
"""Add verbose names to response"""
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
from django.db import ProgrammingError
|
||||||
|
|
||||||
|
from authentik.core.signals import GAUGE_MODELS
|
||||||
|
from authentik.lib.utils.reflection import get_apps
|
||||||
|
|
||||||
|
|
||||||
class AuthentikCoreConfig(AppConfig):
|
class AuthentikCoreConfig(AppConfig):
|
||||||
@ -15,3 +19,12 @@ class AuthentikCoreConfig(AppConfig):
|
|||||||
def ready(self):
|
def ready(self):
|
||||||
import_module("authentik.core.signals")
|
import_module("authentik.core.signals")
|
||||||
import_module("authentik.core.managed")
|
import_module("authentik.core.managed")
|
||||||
|
try:
|
||||||
|
for app in get_apps():
|
||||||
|
for model in app.get_models():
|
||||||
|
GAUGE_MODELS.labels(
|
||||||
|
model_name=model._meta.model_name,
|
||||||
|
app=model._meta.app_label,
|
||||||
|
).set(model.objects.count())
|
||||||
|
except ProgrammingError:
|
||||||
|
pass
|
||||||
|
@ -4,7 +4,7 @@ from channels.generic.websocket import JsonWebsocketConsumer
|
|||||||
from rest_framework.exceptions import AuthenticationFailed
|
from rest_framework.exceptions import AuthenticationFailed
|
||||||
from structlog.stdlib import get_logger
|
from structlog.stdlib import get_logger
|
||||||
|
|
||||||
from authentik.api.auth import token_from_header
|
from authentik.api.authentication import token_from_header
|
||||||
from authentik.core.models import User
|
from authentik.core.models import User
|
||||||
|
|
||||||
LOGGER = get_logger()
|
LOGGER = get_logger()
|
||||||
|
@ -3,23 +3,33 @@ from traceback import format_tb
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
|
from guardian.utils import get_anonymous_user
|
||||||
|
|
||||||
from authentik.core.models import User
|
from authentik.core.models import PropertyMapping, User
|
||||||
from authentik.events.models import Event, EventAction
|
from authentik.events.models import Event, EventAction
|
||||||
from authentik.lib.expression.evaluator import BaseEvaluator
|
from authentik.lib.expression.evaluator import BaseEvaluator
|
||||||
|
from authentik.policies.types import PolicyRequest
|
||||||
|
|
||||||
|
|
||||||
class PropertyMappingEvaluator(BaseEvaluator):
|
class PropertyMappingEvaluator(BaseEvaluator):
|
||||||
"""Custom Evalautor that adds some different context variables."""
|
"""Custom Evalautor that adds some different context variables."""
|
||||||
|
|
||||||
def set_context(
|
def set_context(
|
||||||
self, user: Optional[User], request: Optional[HttpRequest], **kwargs
|
self,
|
||||||
|
user: Optional[User],
|
||||||
|
request: Optional[HttpRequest],
|
||||||
|
mapping: PropertyMapping,
|
||||||
|
**kwargs,
|
||||||
):
|
):
|
||||||
"""Update context with context from PropertyMapping's evaluate"""
|
"""Update context with context from PropertyMapping's evaluate"""
|
||||||
|
req = PolicyRequest(user=get_anonymous_user())
|
||||||
|
req.obj = mapping
|
||||||
if user:
|
if user:
|
||||||
|
req.user = user
|
||||||
self._context["user"] = user
|
self._context["user"] = user
|
||||||
if request:
|
if request:
|
||||||
self._context["request"] = request
|
req.http_request = request
|
||||||
|
self._context["request"] = req
|
||||||
self._context.update(**kwargs)
|
self._context.update(**kwargs)
|
||||||
|
|
||||||
def handle_error(self, exc: Exception, expression_source: str):
|
def handle_error(self, exc: Exception, expression_source: str):
|
||||||
@ -30,9 +40,8 @@ class PropertyMappingEvaluator(BaseEvaluator):
|
|||||||
expression=expression_source,
|
expression=expression_source,
|
||||||
message=error_string,
|
message=error_string,
|
||||||
)
|
)
|
||||||
if "user" in self._context:
|
|
||||||
event.set_user(self._context["user"])
|
|
||||||
if "request" in self._context:
|
if "request" in self._context:
|
||||||
event.from_http(self._context["request"])
|
req: PolicyRequest = self._context["request"]
|
||||||
|
event.from_http(req.http_request, req.user)
|
||||||
return
|
return
|
||||||
event.save()
|
event.save()
|
||||||
|
@ -26,6 +26,8 @@ class ImpersonateMiddleware:
|
|||||||
|
|
||||||
if SESSION_IMPERSONATE_USER in request.session:
|
if SESSION_IMPERSONATE_USER in request.session:
|
||||||
request.user = request.session[SESSION_IMPERSONATE_USER]
|
request.user = request.session[SESSION_IMPERSONATE_USER]
|
||||||
|
# Ensure that the user is active, otherwise nothing will work
|
||||||
|
request.user.is_active = True
|
||||||
|
|
||||||
return self.get_response(request)
|
return self.get_response(request)
|
||||||
|
|
||||||
@ -42,10 +44,14 @@ class RequestIDMiddleware:
|
|||||||
if not hasattr(request, "request_id"):
|
if not hasattr(request, "request_id"):
|
||||||
request_id = uuid4().hex
|
request_id = uuid4().hex
|
||||||
setattr(request, "request_id", request_id)
|
setattr(request, "request_id", request_id)
|
||||||
LOCAL.authentik = {"request_id": request_id}
|
LOCAL.authentik = {
|
||||||
|
"request_id": request_id,
|
||||||
|
"host": request.get_host(),
|
||||||
|
}
|
||||||
response = self.get_response(request)
|
response = self.get_response(request)
|
||||||
response[RESPONSE_HEADER_ID] = request.request_id
|
response[RESPONSE_HEADER_ID] = request.request_id
|
||||||
del LOCAL.authentik["request_id"]
|
del LOCAL.authentik["request_id"]
|
||||||
|
del LOCAL.authentik["host"]
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@ -54,4 +60,5 @@ def structlog_add_request_id(logger: Logger, method_name: str, event_dict):
|
|||||||
"""If threadlocal has authentik defined, add request_id to log"""
|
"""If threadlocal has authentik defined, add request_id to log"""
|
||||||
if hasattr(LOCAL, "authentik"):
|
if hasattr(LOCAL, "authentik"):
|
||||||
event_dict["request_id"] = LOCAL.authentik.get("request_id", "")
|
event_dict["request_id"] = LOCAL.authentik.get("request_id", "")
|
||||||
|
event_dict["host"] = LOCAL.authentik.get("host", "")
|
||||||
return event_dict
|
return event_dict
|
||||||
|
20
authentik/core/migrations/0021_alter_application_slug.py
Normal file
20
authentik/core/migrations/0021_alter_application_slug.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# Generated by Django 3.2.3 on 2021-05-14 08:48
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("authentik_core", "0020_source_user_matching_mode"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="application",
|
||||||
|
name="slug",
|
||||||
|
field=models.SlugField(
|
||||||
|
help_text="Internal application name, used in URLs.", unique=True
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
63
authentik/core/migrations/0022_authenticatedsession.py
Normal file
63
authentik/core/migrations/0022_authenticatedsession.py
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
# Generated by Django 3.2.3 on 2021-05-29 22:14
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.apps.registry import Apps
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
||||||
|
|
||||||
|
import authentik.core.models
|
||||||
|
|
||||||
|
|
||||||
|
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.core.cache import cache
|
||||||
|
|
||||||
|
session_keys = cache.keys(KEY_PREFIX + "*")
|
||||||
|
cache.delete_many(session_keys)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("authentik_core", "0021_alter_application_slug"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="AuthenticatedSession",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"expires",
|
||||||
|
models.DateTimeField(
|
||||||
|
default=authentik.core.models.default_token_duration
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("expiring", models.BooleanField(default=True)),
|
||||||
|
(
|
||||||
|
"uuid",
|
||||||
|
models.UUIDField(
|
||||||
|
default=uuid.uuid4, primary_key=True, serialize=False
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("session_key", models.CharField(max_length=40)),
|
||||||
|
("last_ip", models.TextField()),
|
||||||
|
("last_user_agent", models.TextField(blank=True)),
|
||||||
|
("last_used", models.DateTimeField(auto_now=True)),
|
||||||
|
(
|
||||||
|
"user",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
to=settings.AUTH_USER_MODEL,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
"abstract": False,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.RunPython(migrate_sessions),
|
||||||
|
]
|
@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 3.2.3 on 2021-06-02 21:51
|
||||||
|
|
||||||
|
import django.core.validators
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("authentik_core", "0022_authenticatedsession"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="application",
|
||||||
|
name="meta_launch_url",
|
||||||
|
field=models.TextField(
|
||||||
|
blank=True,
|
||||||
|
default="",
|
||||||
|
validators=[django.core.validators.URLValidator()],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
35
authentik/core/migrations/0024_alter_token_identifier.py
Normal file
35
authentik/core/migrations/0024_alter_token_identifier.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
# Generated by Django 3.2.3 on 2021-06-03 09:33
|
||||||
|
|
||||||
|
from django.apps.registry import Apps
|
||||||
|
from django.db import migrations, models
|
||||||
|
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
||||||
|
from django.db.models import Count
|
||||||
|
|
||||||
|
|
||||||
|
def fix_duplicates(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
||||||
|
db_alias = schema_editor.connection.alias
|
||||||
|
Token = apps.get_model("authentik_core", "token")
|
||||||
|
identifiers = (
|
||||||
|
Token.objects.using(db_alias)
|
||||||
|
.values("identifier")
|
||||||
|
.annotate(identifier_count=Count("identifier"))
|
||||||
|
.filter(identifier_count__gt=1)
|
||||||
|
)
|
||||||
|
for ident in identifiers:
|
||||||
|
Token.objects.using(db_alias).filter(identifier=ident["identifier"]).delete()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("authentik_core", "0023_alter_application_meta_launch_url"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(fix_duplicates),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="token",
|
||||||
|
name="identifier",
|
||||||
|
field=models.SlugField(max_length=255, unique=True),
|
||||||
|
),
|
||||||
|
]
|
@ -0,0 +1,20 @@
|
|||||||
|
# Generated by Django 3.2.3 on 2021-06-05 19:04
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("authentik_core", "0024_alter_token_identifier"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="application",
|
||||||
|
name="meta_icon",
|
||||||
|
field=models.FileField(
|
||||||
|
default=None, null=True, upload_to="application-icons/"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
@ -0,0 +1,20 @@
|
|||||||
|
# Generated by Django 3.2.5 on 2021-07-09 17:27
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("authentik_core", "0025_alter_application_meta_icon"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="application",
|
||||||
|
name="meta_icon",
|
||||||
|
field=models.FileField(
|
||||||
|
default=None, max_length=500, null=True, upload_to="application-icons/"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
@ -5,11 +5,13 @@ from typing import Any, Optional, Type
|
|||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
|
from deepmerge import always_merger
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
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.core import validators
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Q, QuerySet
|
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 cached_property
|
||||||
@ -23,11 +25,11 @@ from structlog.stdlib import get_logger
|
|||||||
|
|
||||||
from authentik.core.exceptions import PropertyMappingExpressionException
|
from authentik.core.exceptions import PropertyMappingExpressionException
|
||||||
from authentik.core.signals import password_changed
|
from authentik.core.signals import password_changed
|
||||||
from authentik.core.types import UILoginButton
|
from authentik.core.types import UILoginButton, UserSettingSerializer
|
||||||
from authentik.flows.challenge import Challenge
|
|
||||||
from authentik.flows.models import Flow
|
from authentik.flows.models import Flow
|
||||||
from authentik.lib.config import CONFIG
|
from authentik.lib.config import CONFIG
|
||||||
from authentik.lib.models import CreatedUpdatedModel, SerializerModel
|
from authentik.lib.models import CreatedUpdatedModel, SerializerModel
|
||||||
|
from authentik.lib.utils.http import get_client_ip
|
||||||
from authentik.managed.models import ManagedModel
|
from authentik.managed.models import ManagedModel
|
||||||
from authentik.policies.models import PolicyBindingModel
|
from authentik.policies.models import PolicyBindingModel
|
||||||
|
|
||||||
@ -35,11 +37,16 @@ LOGGER = get_logger()
|
|||||||
USER_ATTRIBUTE_DEBUG = "goauthentik.io/user/debug"
|
USER_ATTRIBUTE_DEBUG = "goauthentik.io/user/debug"
|
||||||
USER_ATTRIBUTE_SA = "goauthentik.io/user/service-account"
|
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_CAN_OVERRIDE_IP = "goauthentik.io/user/override-ips"
|
||||||
|
|
||||||
GRAVATAR_URL = "https://secure.gravatar.com"
|
GRAVATAR_URL = "https://secure.gravatar.com"
|
||||||
DEFAULT_AVATAR = static("dist/assets/images/user_default.png")
|
DEFAULT_AVATAR = static("dist/assets/images/user_default.png")
|
||||||
|
|
||||||
|
|
||||||
|
options.DEFAULT_NAMES = options.DEFAULT_NAMES + ("authentik_used_by_shadows",)
|
||||||
|
|
||||||
|
|
||||||
def default_token_duration():
|
def default_token_duration():
|
||||||
"""Default duration a Token is valid"""
|
"""Default duration a Token is valid"""
|
||||||
return now() + timedelta(minutes=30)
|
return now() + timedelta(minutes=30)
|
||||||
@ -109,8 +116,8 @@ class User(GuardianUserMixin, AbstractUser):
|
|||||||
including the users attributes"""
|
including the users attributes"""
|
||||||
final_attributes = {}
|
final_attributes = {}
|
||||||
for group in self.ak_groups.all().order_by("name"):
|
for group in self.ak_groups.all().order_by("name"):
|
||||||
final_attributes.update(group.attributes)
|
always_merger.merge(final_attributes, group.attributes)
|
||||||
final_attributes.update(self.attributes)
|
always_merger.merge(final_attributes, self.attributes)
|
||||||
return final_attributes
|
return final_attributes
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
@ -137,21 +144,25 @@ class User(GuardianUserMixin, AbstractUser):
|
|||||||
@property
|
@property
|
||||||
def avatar(self) -> str:
|
def avatar(self) -> str:
|
||||||
"""Get avatar, depending on authentik.avatar setting"""
|
"""Get avatar, depending on authentik.avatar setting"""
|
||||||
mode = CONFIG.raw.get("authentik").get("avatars")
|
mode: str = CONFIG.y("avatars", "none")
|
||||||
if mode == "none":
|
if mode == "none":
|
||||||
return DEFAULT_AVATAR
|
return DEFAULT_AVATAR
|
||||||
|
# gravatar uses md5 for their URLs, so md5 can't be avoided
|
||||||
|
mail_hash = md5(self.email.encode("utf-8")).hexdigest() # nosec
|
||||||
if mode == "gravatar":
|
if mode == "gravatar":
|
||||||
parameters = [
|
parameters = [
|
||||||
("s", "158"),
|
("s", "158"),
|
||||||
("r", "g"),
|
("r", "g"),
|
||||||
]
|
]
|
||||||
# gravatar uses md5 for their URLs, so md5 can't be avoided
|
|
||||||
mail_hash = md5(self.email.encode("utf-8")).hexdigest() # nosec
|
|
||||||
gravatar_url = (
|
gravatar_url = (
|
||||||
f"{GRAVATAR_URL}/avatar/{mail_hash}?{urlencode(parameters, doseq=True)}"
|
f"{GRAVATAR_URL}/avatar/{mail_hash}?{urlencode(parameters, doseq=True)}"
|
||||||
)
|
)
|
||||||
return escape(gravatar_url)
|
return escape(gravatar_url)
|
||||||
raise ValueError(f"Invalid avatar mode {mode}")
|
return mode % {
|
||||||
|
"username": self.username,
|
||||||
|
"mail_hash": mail_hash,
|
||||||
|
"upn": self.attributes.get("upn", ""),
|
||||||
|
}
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
||||||
@ -207,17 +218,38 @@ class Application(PolicyBindingModel):
|
|||||||
add custom fields and other properties"""
|
add custom fields and other properties"""
|
||||||
|
|
||||||
name = models.TextField(help_text=_("Application's display Name."))
|
name = models.TextField(help_text=_("Application's display Name."))
|
||||||
slug = models.SlugField(help_text=_("Internal application name, used in URLs."))
|
slug = models.SlugField(
|
||||||
|
help_text=_("Internal application name, used in URLs."), unique=True
|
||||||
|
)
|
||||||
provider = models.OneToOneField(
|
provider = models.OneToOneField(
|
||||||
"Provider", null=True, blank=True, default=None, on_delete=models.SET_DEFAULT
|
"Provider", null=True, blank=True, default=None, on_delete=models.SET_DEFAULT
|
||||||
)
|
)
|
||||||
|
|
||||||
meta_launch_url = models.URLField(default="", blank=True)
|
meta_launch_url = models.TextField(
|
||||||
|
default="", blank=True, validators=[validators.URLValidator()]
|
||||||
|
)
|
||||||
# For template applications, this can be set to /static/authentik/applications/*
|
# For template applications, this can be set to /static/authentik/applications/*
|
||||||
meta_icon = models.FileField(upload_to="application-icons/", default="", blank=True)
|
meta_icon = models.FileField(
|
||||||
|
upload_to="application-icons/",
|
||||||
|
default=None,
|
||||||
|
null=True,
|
||||||
|
max_length=500,
|
||||||
|
)
|
||||||
meta_description = models.TextField(default="", blank=True)
|
meta_description = models.TextField(default="", blank=True)
|
||||||
meta_publisher = models.TextField(default="", blank=True)
|
meta_publisher = models.TextField(default="", blank=True)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def get_meta_icon(self) -> Optional[str]:
|
||||||
|
"""Get the URL to the App Icon image. If the name is /static or starts with http
|
||||||
|
it is returned as-is"""
|
||||||
|
if not self.meta_icon:
|
||||||
|
return None
|
||||||
|
if self.meta_icon.name.startswith("http") or self.meta_icon.name.startswith(
|
||||||
|
"/static"
|
||||||
|
):
|
||||||
|
return self.meta_icon.name
|
||||||
|
return self.meta_icon.url
|
||||||
|
|
||||||
def get_launch_url(self) -> Optional[str]:
|
def get_launch_url(self) -> 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."""
|
||||||
if self.meta_launch_url:
|
if self.meta_launch_url:
|
||||||
@ -322,9 +354,9 @@ class Source(ManagedModel, SerializerModel, PolicyBindingModel):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ui_user_settings(self) -> Optional[Challenge]:
|
def ui_user_settings(self) -> Optional[UserSettingSerializer]:
|
||||||
"""Entrypoint to integrate with User settings. Can either return None if no
|
"""Entrypoint to integrate with User settings. Can either return None if no
|
||||||
user settings are available, or a challenge."""
|
user settings are available, or UserSettingSerializer."""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@ -350,6 +382,13 @@ class ExpiringModel(models.Model):
|
|||||||
expires = models.DateTimeField(default=default_token_duration)
|
expires = models.DateTimeField(default=default_token_duration)
|
||||||
expiring = models.BooleanField(default=True)
|
expiring = models.BooleanField(default=True)
|
||||||
|
|
||||||
|
def expire_action(self, *args, **kwargs):
|
||||||
|
"""Handler which is called when this object is expired. By
|
||||||
|
default the object is deleted. This is less efficient compared
|
||||||
|
to bulk deleting objects, but classes like Token() need to change
|
||||||
|
values instead of being deleted."""
|
||||||
|
return self.delete(*args, **kwargs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def filter_not_expired(cls, **kwargs) -> QuerySet:
|
def filter_not_expired(cls, **kwargs) -> QuerySet:
|
||||||
"""Filer for tokens which are not expired yet or are not expiring,
|
"""Filer for tokens which are not expired yet or are not expiring,
|
||||||
@ -386,7 +425,7 @@ class Token(ManagedModel, ExpiringModel):
|
|||||||
"""Token used to authenticate the User for API Access or confirm another Stage like Email."""
|
"""Token used to authenticate the User for API Access or confirm another Stage like Email."""
|
||||||
|
|
||||||
token_uuid = models.UUIDField(primary_key=True, editable=False, default=uuid4)
|
token_uuid = models.UUIDField(primary_key=True, editable=False, default=uuid4)
|
||||||
identifier = models.SlugField(max_length=255)
|
identifier = models.SlugField(max_length=255, unique=True)
|
||||||
key = models.TextField(default=default_token_key)
|
key = models.TextField(default=default_token_key)
|
||||||
intent = models.TextField(
|
intent = models.TextField(
|
||||||
choices=TokenIntents.choices, default=TokenIntents.INTENT_VERIFICATION
|
choices=TokenIntents.choices, default=TokenIntents.INTENT_VERIFICATION
|
||||||
@ -394,6 +433,19 @@ class Token(ManagedModel, ExpiringModel):
|
|||||||
user = models.ForeignKey("User", on_delete=models.CASCADE, related_name="+")
|
user = models.ForeignKey("User", on_delete=models.CASCADE, related_name="+")
|
||||||
description = models.TextField(default="", blank=True)
|
description = models.TextField(default="", blank=True)
|
||||||
|
|
||||||
|
def expire_action(self, *args, **kwargs):
|
||||||
|
"""Handler which is called when this object is expired."""
|
||||||
|
from authentik.events.models import Event, EventAction
|
||||||
|
|
||||||
|
self.key = default_token_key()
|
||||||
|
self.expires = default_token_duration()
|
||||||
|
self.save(*args, **kwargs)
|
||||||
|
Event.new(
|
||||||
|
action=EventAction.SECRET_ROTATE,
|
||||||
|
token=self,
|
||||||
|
message=f"Token {self.identifier}'s secret was rotated.",
|
||||||
|
).save()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
description = f"{self.identifier}"
|
description = f"{self.identifier}"
|
||||||
if self.expiring:
|
if self.expiring:
|
||||||
@ -437,11 +489,11 @@ class PropertyMapping(SerializerModel, ManagedModel):
|
|||||||
from authentik.core.expression import PropertyMappingEvaluator
|
from authentik.core.expression import PropertyMappingEvaluator
|
||||||
|
|
||||||
evaluator = PropertyMappingEvaluator()
|
evaluator = PropertyMappingEvaluator()
|
||||||
evaluator.set_context(user, request, **kwargs)
|
evaluator.set_context(user, request, self, **kwargs)
|
||||||
try:
|
try:
|
||||||
return evaluator.evaluate(self.expression)
|
return evaluator.evaluate(self.expression)
|
||||||
except (ValueError, SyntaxError) as exc:
|
except Exception as exc:
|
||||||
raise PropertyMappingExpressionException from exc
|
raise PropertyMappingExpressionException(str(exc)) from exc
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"Property Mapping {self.name}"
|
return f"Property Mapping {self.name}"
|
||||||
@ -450,3 +502,37 @@ class PropertyMapping(SerializerModel, ManagedModel):
|
|||||||
|
|
||||||
verbose_name = _("Property Mapping")
|
verbose_name = _("Property Mapping")
|
||||||
verbose_name_plural = _("Property Mappings")
|
verbose_name_plural = _("Property Mappings")
|
||||||
|
|
||||||
|
|
||||||
|
class AuthenticatedSession(ExpiringModel):
|
||||||
|
"""Additional session class for authenticated users. Augments the standard django session
|
||||||
|
to achieve the following:
|
||||||
|
- Make it queryable by user
|
||||||
|
- Have a direct connection to user objects
|
||||||
|
- Allow users to view their own sessions and terminate them
|
||||||
|
- Save structured and well-defined information.
|
||||||
|
"""
|
||||||
|
|
||||||
|
uuid = models.UUIDField(default=uuid4, primary_key=True)
|
||||||
|
|
||||||
|
session_key = models.CharField(max_length=40)
|
||||||
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
last_ip = models.TextField()
|
||||||
|
last_user_agent = models.TextField(blank=True)
|
||||||
|
last_used = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_request(
|
||||||
|
request: HttpRequest, user: User
|
||||||
|
) -> Optional["AuthenticatedSession"]:
|
||||||
|
"""Create a new session from a http request"""
|
||||||
|
if not hasattr(request, "session") or not request.session.session_key:
|
||||||
|
return None
|
||||||
|
return AuthenticatedSession(
|
||||||
|
session_key=request.session.session_key,
|
||||||
|
user=user,
|
||||||
|
last_ip=get_client_ip(request),
|
||||||
|
last_user_agent=request.META.get("HTTP_USER_AGENT", ""),
|
||||||
|
expires=request.session.get_expiry_date(),
|
||||||
|
)
|
||||||
|
@ -1,20 +1,39 @@
|
|||||||
"""authentik core signals"""
|
"""authentik core signals"""
|
||||||
|
from typing import TYPE_CHECKING, Type
|
||||||
|
|
||||||
|
from django.contrib.auth.signals import user_logged_in, user_logged_out
|
||||||
|
from django.contrib.sessions.backends.cache import KEY_PREFIX
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.core.signals import Signal
|
from django.core.signals import Signal
|
||||||
from django.db.models.signals import post_save
|
from django.db.models import Model
|
||||||
|
from django.db.models.signals import post_save, pre_delete
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
|
from django.http.request import HttpRequest
|
||||||
|
from prometheus_client import Gauge
|
||||||
|
|
||||||
# Arguments: user: User, password: str
|
# Arguments: user: User, password: str
|
||||||
password_changed = Signal()
|
password_changed = Signal()
|
||||||
|
|
||||||
|
GAUGE_MODELS = Gauge(
|
||||||
|
"authentik_models", "Count of various objects", ["model_name", "app"]
|
||||||
|
)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from authentik.core.models import AuthenticatedSession, User
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save)
|
@receiver(post_save)
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def post_save_application(sender, instance, created: bool, **_):
|
def post_save_application(sender: type[Model], instance, created: bool, **_):
|
||||||
"""Clear user's application cache upon application creation"""
|
"""Clear user's application cache upon application creation"""
|
||||||
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
|
||||||
@ -22,3 +41,39 @@ def post_save_application(sender, instance, created: bool, **_):
|
|||||||
# Also delete user application cache
|
# Also delete user application cache
|
||||||
keys = cache.keys(user_app_cache_key("*"))
|
keys = cache.keys(user_app_cache_key("*"))
|
||||||
cache.delete_many(keys)
|
cache.delete_many(keys)
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(user_logged_in)
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def user_logged_in_session(sender, request: HttpRequest, user: "User", **_):
|
||||||
|
"""Create an AuthenticatedSession from request"""
|
||||||
|
from authentik.core.models import AuthenticatedSession
|
||||||
|
|
||||||
|
session = AuthenticatedSession.from_request(request, user)
|
||||||
|
if session:
|
||||||
|
session.save()
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(user_logged_out)
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def user_logged_out_session(sender, request: HttpRequest, user: "User", **_):
|
||||||
|
"""Delete AuthenticatedSession if it exists"""
|
||||||
|
from authentik.core.models import AuthenticatedSession
|
||||||
|
|
||||||
|
AuthenticatedSession.objects.filter(
|
||||||
|
session_key=request.session.session_key
|
||||||
|
).delete()
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(pre_delete)
|
||||||
|
def authenticated_session_delete(
|
||||||
|
sender: Type[Model], instance: "AuthenticatedSession", **_
|
||||||
|
):
|
||||||
|
"""Delete session when authenticated session is deleted"""
|
||||||
|
from authentik.core.models import AuthenticatedSession
|
||||||
|
|
||||||
|
if sender != AuthenticatedSession:
|
||||||
|
return
|
||||||
|
|
||||||
|
cache_key = f"{KEY_PREFIX}{instance.session_key}"
|
||||||
|
cache.delete(cache_key)
|
||||||
|
@ -33,6 +33,7 @@ from authentik.flows.planner import (
|
|||||||
from authentik.flows.views import NEXT_ARG_NAME, SESSION_KEY_GET, SESSION_KEY_PLAN
|
from authentik.flows.views 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.utils import delete_none_keys
|
from authentik.policies.utils import delete_none_keys
|
||||||
|
from authentik.stages.password import BACKEND_DJANGO
|
||||||
from authentik.stages.password.stage import PLAN_CONTEXT_AUTHENTICATION_BACKEND
|
from authentik.stages.password.stage import PLAN_CONTEXT_AUTHENTICATION_BACKEND
|
||||||
from authentik.stages.prompt.stage import PLAN_CONTEXT_PROMPT
|
from authentik.stages.prompt.stage import PLAN_CONTEXT_PROMPT
|
||||||
|
|
||||||
@ -140,11 +141,11 @@ class SourceFlowManager:
|
|||||||
self._logger.info("denying source because user exists", user=user)
|
self._logger.info("denying source because user exists", user=user)
|
||||||
return Action.DENY, None
|
return Action.DENY, None
|
||||||
# Should never get here as default enroll case is returned above.
|
# Should never get here as default enroll case is returned above.
|
||||||
return Action.DENY, None
|
return Action.DENY, None # pragma: no cover
|
||||||
|
|
||||||
def update_connection(
|
def update_connection(
|
||||||
self, connection: UserSourceConnection, **kwargs
|
self, connection: UserSourceConnection, **kwargs
|
||||||
) -> UserSourceConnection:
|
) -> UserSourceConnection: # pragma: no cover
|
||||||
"""Optionally make changes to the connection after it is looked up/created."""
|
"""Optionally make changes to the connection after it is looked up/created."""
|
||||||
return connection
|
return connection
|
||||||
|
|
||||||
@ -177,11 +178,13 @@ class SourceFlowManager:
|
|||||||
% {"source": self.source.name}
|
% {"source": self.source.name}
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return redirect("/")
|
return redirect(reverse("authentik_core:root-redirect"))
|
||||||
|
|
||||||
# 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]:
|
||||||
"""Hook to override stages which are appended to the flow"""
|
"""Hook to override stages which are appended to the flow"""
|
||||||
|
if not self.source.enrollment_flow:
|
||||||
|
return []
|
||||||
if flow.slug == self.source.enrollment_flow.slug:
|
if flow.slug == self.source.enrollment_flow.slug:
|
||||||
return [
|
return [
|
||||||
in_memory_stage(PostUserEnrollmentStage),
|
in_memory_stage(PostUserEnrollmentStage),
|
||||||
@ -198,7 +201,7 @@ class SourceFlowManager:
|
|||||||
kwargs.update(
|
kwargs.update(
|
||||||
{
|
{
|
||||||
# Since we authenticate the user by their token, they have no backend set
|
# Since we authenticate the user by their token, they have no backend set
|
||||||
PLAN_CONTEXT_AUTHENTICATION_BACKEND: "django.contrib.auth.backends.ModelBackend",
|
PLAN_CONTEXT_AUTHENTICATION_BACKEND: BACKEND_DJANGO,
|
||||||
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,
|
||||||
@ -210,7 +213,7 @@ class SourceFlowManager:
|
|||||||
planner = FlowPlanner(flow)
|
planner = FlowPlanner(flow)
|
||||||
plan = planner.plan(self.request, kwargs)
|
plan = planner.plan(self.request, kwargs)
|
||||||
for stage in self.get_stages_to_append(flow):
|
for stage in self.get_stages_to_append(flow):
|
||||||
plan.append(stage)
|
plan.append_stage(stage=stage)
|
||||||
self.request.session[SESSION_KEY_PLAN] = plan
|
self.request.session[SESSION_KEY_PLAN] = plan
|
||||||
return redirect_with_qs(
|
return redirect_with_qs(
|
||||||
"authentik_core:if-flow",
|
"authentik_core:if-flow",
|
||||||
|
@ -26,14 +26,16 @@ def clean_expired_models(self: MonitoredTask):
|
|||||||
messages = []
|
messages = []
|
||||||
for cls in ExpiringModel.__subclasses__():
|
for cls in ExpiringModel.__subclasses__():
|
||||||
cls: ExpiringModel
|
cls: ExpiringModel
|
||||||
amount, _ = (
|
objects = (
|
||||||
cls.objects.all()
|
cls.objects.all()
|
||||||
.exclude(expiring=False)
|
.exclude(expiring=False)
|
||||||
.exclude(expiring=True, expires__gt=now())
|
.exclude(expiring=True, expires__gt=now())
|
||||||
.delete()
|
|
||||||
)
|
)
|
||||||
LOGGER.debug("Deleted expired models", model=cls, amount=amount)
|
for obj in objects:
|
||||||
messages.append(f"Deleted {amount} expired {cls._meta.verbose_name_plural}")
|
obj.expire_action()
|
||||||
|
amount = objects.count()
|
||||||
|
LOGGER.debug("Expired models", model=cls, amount=amount)
|
||||||
|
messages.append(f"Expired {amount} {cls._meta.verbose_name_plural}")
|
||||||
self.set_status(TaskResult(TaskResultStatus.SUCCESSFUL, messages))
|
self.set_status(TaskResult(TaskResultStatus.SUCCESSFUL, messages))
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,8 +7,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||||
<title>{% block title %}{% trans title|default:config.authentik.branding.title %}{% endblock %}</title>
|
<title>{% block title %}{% trans title|default:tenant.branding_title %}{% endblock %}</title>
|
||||||
<link rel="icon" type="image/png" href="{% static 'dist/assets/icons/icon.png' %}?v={{ ak_version }}">
|
|
||||||
<link rel="shortcut icon" type="image/png" href="{% static 'dist/assets/icons/icon.png' %}?v={{ ak_version }}">
|
<link rel="shortcut icon" type="image/png" href="{% static 'dist/assets/icons/icon.png' %}?v={{ ak_version }}">
|
||||||
<link rel="stylesheet" type="text/css" href="{% static 'dist/patternfly-base.css' %}?v={{ ak_version }}">
|
<link rel="stylesheet" type="text/css" href="{% static 'dist/patternfly-base.css' %}?v={{ ak_version }}">
|
||||||
<link rel="stylesheet" type="text/css" href="{% static 'dist/page.css' %}?v={{ ak_version }}">
|
<link rel="stylesheet" type="text/css" href="{% static 'dist/page.css' %}?v={{ ak_version }}">
|
||||||
|
@ -3,18 +3,8 @@
|
|||||||
{% load static %}
|
{% load static %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block head %}
|
|
||||||
{{ block.super }}
|
|
||||||
<style>
|
|
||||||
.pf-c-background-image::before {
|
|
||||||
background-image: url("{% static 'dist/assets/images/flow_background.jpg' %}");
|
|
||||||
background-position: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
{% trans 'End session' %} - {{ config.authentik.branding.title }}
|
{% trans 'End session' %} - {{ tenant.branding_title }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block card_title %}
|
{% block card_title %}
|
@ -4,11 +4,18 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block head_before %}
|
{% block head_before %}
|
||||||
|
{% if flow.compatibility_mode %}
|
||||||
<script>ShadyDOM = { force: !navigator.webdriver };</script>
|
<script>ShadyDOM = { force: !navigator.webdriver };</script>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block head %}
|
{% block head %}
|
||||||
<script src="{% static 'dist/FlowInterface.js' %}?v={{ ak_version }}" type="module"></script>
|
<script src="{% static 'dist/FlowInterface.js' %}?v={{ ak_version }}" type="module"></script>
|
||||||
|
<style>
|
||||||
|
.pf-c-background-image::before {
|
||||||
|
--ak-flow-background: url("{{ flow.background_url }}");
|
||||||
|
}
|
||||||
|
</style>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
@ -7,6 +7,14 @@
|
|||||||
<link rel="stylesheet" type="text/css" href="{% static 'dist/patternfly.min.css' %}?v={{ ak_version }}">
|
<link rel="stylesheet" type="text/css" href="{% static 'dist/patternfly.min.css' %}?v={{ ak_version }}">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block head %}
|
||||||
|
<style>
|
||||||
|
.pf-c-background-image::before {
|
||||||
|
--ak-flow-background: url("/static/dist/assets/images/flow_background.jpg");
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<div class="pf-c-background-image">
|
<div class="pf-c-background-image">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" class="pf-c-background-image__filter" width="0" height="0">
|
<svg xmlns="http://www.w3.org/2000/svg" class="pf-c-background-image__filter" width="0" height="0">
|
||||||
@ -26,10 +34,7 @@
|
|||||||
<div class="ak-login-container">
|
<div class="ak-login-container">
|
||||||
<header class="pf-c-login__header">
|
<header class="pf-c-login__header">
|
||||||
<div class="pf-c-brand ak-brand">
|
<div class="pf-c-brand ak-brand">
|
||||||
<img src="{{ config.authentik.branding.logo }}" alt="authentik icon" />
|
<img src="{{ tenant.branding_logo }}" alt="authentik icon" />
|
||||||
{% if config.authentik.branding.title_show %}
|
|
||||||
<p>{{ config.authentik.branding.title }}</p>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
{% block main_container %}
|
{% block main_container %}
|
||||||
@ -49,12 +54,12 @@
|
|||||||
<footer class="pf-c-login__footer">
|
<footer class="pf-c-login__footer">
|
||||||
<p></p>
|
<p></p>
|
||||||
<ul class="pf-c-list pf-m-inline">
|
<ul class="pf-c-list pf-m-inline">
|
||||||
{% for link in config.authentik.footer_links %}
|
{% for link in footer_links %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ link.href }}">{{ link.name }}</a>
|
<a href="{{ link.href }}">{{ link.name }}</a>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if config.authentik.branding.title != "authentik" %}
|
{% if tenant.branding_title != "authentik" %}
|
||||||
<li>
|
<li>
|
||||||
<a href="https://goauthentik.io">
|
<a href="https://goauthentik.io">
|
||||||
{% trans 'Powered by authentik' %}
|
{% trans 'Powered by authentik' %}
|
||||||
|
@ -32,14 +32,20 @@ class TestApplicationsAPI(APITestCase):
|
|||||||
kwargs={"slug": self.allowed.slug},
|
kwargs={"slug": self.allowed.slug},
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 204)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertJSONEqual(
|
||||||
|
force_str(response.content), {"messages": [], "passing": True}
|
||||||
|
)
|
||||||
response = self.client.get(
|
response = self.client.get(
|
||||||
reverse(
|
reverse(
|
||||||
"authentik_api:application-check-access",
|
"authentik_api:application-check-access",
|
||||||
kwargs={"slug": self.denied.slug},
|
kwargs={"slug": self.denied.slug},
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertJSONEqual(
|
||||||
|
force_str(response.content), {"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"""
|
||||||
|
31
authentik/core/tests/test_authenticated_sessions_api.py
Normal file
31
authentik/core/tests/test_authenticated_sessions_api.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
"""Test AuthenticatedSessions API"""
|
||||||
|
from json import loads
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
class TestAuthenticatedSessionsAPI(APITestCase):
|
||||||
|
"""Test AuthenticatedSessions API"""
|
||||||
|
|
||||||
|
def setUp(self) -> None:
|
||||||
|
super().setUp()
|
||||||
|
self.user = User.objects.get(username="akadmin")
|
||||||
|
self.other_user = User.objects.create(username="normal-user")
|
||||||
|
|
||||||
|
def test_list(self):
|
||||||
|
"""Test session list endpoint"""
|
||||||
|
self.client.force_login(self.user)
|
||||||
|
response = self.client.get(reverse("authentik_api:authenticatedsession-list"))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_non_admin_list(self):
|
||||||
|
"""Test non-admin list"""
|
||||||
|
self.client.force_login(self.other_user)
|
||||||
|
response = self.client.get(reverse("authentik_api:authenticatedsession-list"))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
body = loads(force_str(response.content))
|
||||||
|
self.assertEqual(body["pagination"]["count"], 1)
|
@ -17,6 +17,9 @@ class TestImpersonation(TestCase):
|
|||||||
|
|
||||||
def test_impersonate_simple(self):
|
def test_impersonate_simple(self):
|
||||||
"""test simple impersonation and un-impersonation"""
|
"""test simple impersonation and un-impersonation"""
|
||||||
|
# test with an inactive user to ensure that still works
|
||||||
|
self.other_user.is_active = False
|
||||||
|
self.other_user.save()
|
||||||
self.client.force_login(self.akadmin)
|
self.client.force_login(self.akadmin)
|
||||||
|
|
||||||
self.client.get(
|
self.client.get(
|
||||||
|
@ -31,7 +31,7 @@ class TestPropertyMappings(TestCase):
|
|||||||
"""Test expression error"""
|
"""Test expression error"""
|
||||||
expr = "return aaa"
|
expr = "return aaa"
|
||||||
mapping = PropertyMapping.objects.create(name="test", expression=expr)
|
mapping = PropertyMapping.objects.create(name="test", expression=expr)
|
||||||
with self.assertRaises(NameError):
|
with self.assertRaises(PropertyMappingExpressionException):
|
||||||
mapping.evaluate(None, None)
|
mapping.evaluate(None, None)
|
||||||
events = Event.objects.filter(
|
events = Event.objects.filter(
|
||||||
action=EventAction.PROPERTY_MAPPING_EXCEPTION, context__expression=expr
|
action=EventAction.PROPERTY_MAPPING_EXCEPTION, context__expression=expr
|
||||||
@ -44,7 +44,7 @@ class TestPropertyMappings(TestCase):
|
|||||||
expr = "return aaa"
|
expr = "return aaa"
|
||||||
request = self.factory.get("/")
|
request = self.factory.get("/")
|
||||||
mapping = PropertyMapping.objects.create(name="test", expression=expr)
|
mapping = PropertyMapping.objects.create(name="test", expression=expr)
|
||||||
with self.assertRaises(NameError):
|
with self.assertRaises(PropertyMappingExpressionException):
|
||||||
mapping.evaluate(get_anonymous_user(), request)
|
mapping.evaluate(get_anonymous_user(), request)
|
||||||
events = Event.objects.filter(
|
events = Event.objects.filter(
|
||||||
action=EventAction.PROPERTY_MAPPING_EXCEPTION, context__expression=expr
|
action=EventAction.PROPERTY_MAPPING_EXCEPTION, context__expression=expr
|
||||||
|
160
authentik/core/tests/test_source_flow_manager.py
Normal file
160
authentik/core/tests/test_source_flow_manager.py
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
"""Test Source flow_manager"""
|
||||||
|
from django.contrib.auth.models import AnonymousUser
|
||||||
|
from django.contrib.messages.middleware import MessageMiddleware
|
||||||
|
from django.contrib.sessions.middleware import SessionMiddleware
|
||||||
|
from django.http.request import HttpRequest
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.test.client import RequestFactory
|
||||||
|
from guardian.utils import get_anonymous_user
|
||||||
|
|
||||||
|
from authentik.core.models import SourceUserMatchingModes, User
|
||||||
|
from authentik.core.sources.flow_manager import Action
|
||||||
|
from authentik.flows.tests.test_planner import dummy_get_response
|
||||||
|
from authentik.providers.oauth2.generators import generate_client_id
|
||||||
|
from authentik.sources.oauth.models import OAuthSource, UserOAuthSourceConnection
|
||||||
|
from authentik.sources.oauth.views.callback import OAuthSourceFlowManager
|
||||||
|
|
||||||
|
|
||||||
|
class TestSourceFlowManager(TestCase):
|
||||||
|
"""Test Source flow_manager"""
|
||||||
|
|
||||||
|
def setUp(self) -> None:
|
||||||
|
super().setUp()
|
||||||
|
self.source = OAuthSource.objects.create(name="test")
|
||||||
|
self.factory = RequestFactory()
|
||||||
|
self.identifier = generate_client_id()
|
||||||
|
|
||||||
|
def get_request(self, user: User) -> HttpRequest:
|
||||||
|
"""Helper to create a get request with session and message middleware"""
|
||||||
|
request = self.factory.get("/")
|
||||||
|
request.user = user
|
||||||
|
middleware = SessionMiddleware(dummy_get_response)
|
||||||
|
middleware.process_request(request)
|
||||||
|
request.session.save()
|
||||||
|
middleware = MessageMiddleware(dummy_get_response)
|
||||||
|
middleware.process_request(request)
|
||||||
|
request.session.save()
|
||||||
|
return request
|
||||||
|
|
||||||
|
def test_unauthenticated_enroll(self):
|
||||||
|
"""Test un-authenticated user enrolling"""
|
||||||
|
flow_manager = OAuthSourceFlowManager(
|
||||||
|
self.source, self.get_request(AnonymousUser()), self.identifier, {}
|
||||||
|
)
|
||||||
|
action, _ = flow_manager.get_action()
|
||||||
|
self.assertEqual(action, Action.ENROLL)
|
||||||
|
flow_manager.get_flow()
|
||||||
|
|
||||||
|
def test_unauthenticated_auth(self):
|
||||||
|
"""Test un-authenticated user authenticating"""
|
||||||
|
UserOAuthSourceConnection.objects.create(
|
||||||
|
user=get_anonymous_user(), source=self.source, identifier=self.identifier
|
||||||
|
)
|
||||||
|
|
||||||
|
flow_manager = OAuthSourceFlowManager(
|
||||||
|
self.source, self.get_request(AnonymousUser()), self.identifier, {}
|
||||||
|
)
|
||||||
|
action, _ = flow_manager.get_action()
|
||||||
|
self.assertEqual(action, Action.AUTH)
|
||||||
|
flow_manager.get_flow()
|
||||||
|
|
||||||
|
def test_authenticated_link(self):
|
||||||
|
"""Test authenticated user linking"""
|
||||||
|
UserOAuthSourceConnection.objects.create(
|
||||||
|
user=get_anonymous_user(), source=self.source, identifier=self.identifier
|
||||||
|
)
|
||||||
|
user = User.objects.create(username="foo", email="foo@bar.baz")
|
||||||
|
flow_manager = OAuthSourceFlowManager(
|
||||||
|
self.source, self.get_request(user), self.identifier, {}
|
||||||
|
)
|
||||||
|
action, _ = flow_manager.get_action()
|
||||||
|
self.assertEqual(action, Action.LINK)
|
||||||
|
flow_manager.get_flow()
|
||||||
|
|
||||||
|
def test_unauthenticated_enroll_email(self):
|
||||||
|
"""Test un-authenticated user enrolling (link on email)"""
|
||||||
|
User.objects.create(username="foo", email="foo@bar.baz")
|
||||||
|
self.source.user_matching_mode = SourceUserMatchingModes.EMAIL_LINK
|
||||||
|
|
||||||
|
# Without email, deny
|
||||||
|
flow_manager = OAuthSourceFlowManager(
|
||||||
|
self.source, self.get_request(AnonymousUser()), self.identifier, {}
|
||||||
|
)
|
||||||
|
action, _ = flow_manager.get_action()
|
||||||
|
self.assertEqual(action, Action.DENY)
|
||||||
|
flow_manager.get_flow()
|
||||||
|
# With email
|
||||||
|
flow_manager = OAuthSourceFlowManager(
|
||||||
|
self.source,
|
||||||
|
self.get_request(AnonymousUser()),
|
||||||
|
self.identifier,
|
||||||
|
{"email": "foo@bar.baz"},
|
||||||
|
)
|
||||||
|
action, _ = flow_manager.get_action()
|
||||||
|
self.assertEqual(action, Action.LINK)
|
||||||
|
flow_manager.get_flow()
|
||||||
|
|
||||||
|
def test_unauthenticated_enroll_username(self):
|
||||||
|
"""Test un-authenticated user enrolling (link on username)"""
|
||||||
|
User.objects.create(username="foo", email="foo@bar.baz")
|
||||||
|
self.source.user_matching_mode = SourceUserMatchingModes.USERNAME_LINK
|
||||||
|
|
||||||
|
# Without username, deny
|
||||||
|
flow_manager = OAuthSourceFlowManager(
|
||||||
|
self.source, self.get_request(AnonymousUser()), self.identifier, {}
|
||||||
|
)
|
||||||
|
action, _ = flow_manager.get_action()
|
||||||
|
self.assertEqual(action, Action.DENY)
|
||||||
|
flow_manager.get_flow()
|
||||||
|
# With username
|
||||||
|
flow_manager = OAuthSourceFlowManager(
|
||||||
|
self.source,
|
||||||
|
self.get_request(AnonymousUser()),
|
||||||
|
self.identifier,
|
||||||
|
{"username": "foo"},
|
||||||
|
)
|
||||||
|
action, _ = flow_manager.get_action()
|
||||||
|
self.assertEqual(action, Action.LINK)
|
||||||
|
flow_manager.get_flow()
|
||||||
|
|
||||||
|
def test_unauthenticated_enroll_username_deny(self):
|
||||||
|
"""Test un-authenticated user enrolling (deny on username)"""
|
||||||
|
User.objects.create(username="foo", email="foo@bar.baz")
|
||||||
|
self.source.user_matching_mode = SourceUserMatchingModes.USERNAME_DENY
|
||||||
|
|
||||||
|
# With non-existent username, enroll
|
||||||
|
flow_manager = OAuthSourceFlowManager(
|
||||||
|
self.source,
|
||||||
|
self.get_request(AnonymousUser()),
|
||||||
|
self.identifier,
|
||||||
|
{
|
||||||
|
"username": "bar",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
action, _ = flow_manager.get_action()
|
||||||
|
self.assertEqual(action, Action.ENROLL)
|
||||||
|
flow_manager.get_flow()
|
||||||
|
# With username
|
||||||
|
flow_manager = OAuthSourceFlowManager(
|
||||||
|
self.source,
|
||||||
|
self.get_request(AnonymousUser()),
|
||||||
|
self.identifier,
|
||||||
|
{"username": "foo"},
|
||||||
|
)
|
||||||
|
action, _ = flow_manager.get_action()
|
||||||
|
self.assertEqual(action, Action.DENY)
|
||||||
|
flow_manager.get_flow()
|
||||||
|
|
||||||
|
def test_unauthenticated_enroll_link_non_existent(self):
|
||||||
|
"""Test un-authenticated user enrolling (link on username), username doesn't exist"""
|
||||||
|
self.source.user_matching_mode = SourceUserMatchingModes.USERNAME_LINK
|
||||||
|
|
||||||
|
flow_manager = OAuthSourceFlowManager(
|
||||||
|
self.source,
|
||||||
|
self.get_request(AnonymousUser()),
|
||||||
|
self.identifier,
|
||||||
|
{"username": "foo"},
|
||||||
|
)
|
||||||
|
action, _ = flow_manager.get_action()
|
||||||
|
self.assertEqual(action, Action.ENROLL)
|
||||||
|
flow_manager.get_flow()
|
@ -1,18 +0,0 @@
|
|||||||
"""authentik core task tests"""
|
|
||||||
from django.test import TestCase
|
|
||||||
from django.utils.timezone import now
|
|
||||||
from guardian.shortcuts import get_anonymous_user
|
|
||||||
|
|
||||||
from authentik.core.models import Token
|
|
||||||
from authentik.core.tasks import clean_expired_models
|
|
||||||
|
|
||||||
|
|
||||||
class TestTasks(TestCase):
|
|
||||||
"""Test Tasks"""
|
|
||||||
|
|
||||||
def test_token_cleanup(self):
|
|
||||||
"""Test Token cleanup task"""
|
|
||||||
Token.objects.create(expires=now(), user=get_anonymous_user())
|
|
||||||
self.assertEqual(Token.objects.all().count(), 1)
|
|
||||||
clean_expired_models.delay().get()
|
|
||||||
self.assertEqual(Token.objects.all().count(), 0)
|
|
@ -1,8 +1,16 @@
|
|||||||
"""Test token API"""
|
"""Test token API"""
|
||||||
from django.urls.base import reverse
|
from django.urls.base import reverse
|
||||||
|
from django.utils.timezone import now
|
||||||
|
from guardian.shortcuts import get_anonymous_user
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
|
|
||||||
from authentik.core.models import Token, TokenIntents, User
|
from authentik.core.models import (
|
||||||
|
USER_ATTRIBUTE_TOKEN_EXPIRING,
|
||||||
|
Token,
|
||||||
|
TokenIntents,
|
||||||
|
User,
|
||||||
|
)
|
||||||
|
from authentik.core.tasks import clean_expired_models
|
||||||
|
|
||||||
|
|
||||||
class TestTokenAPI(APITestCase):
|
class TestTokenAPI(APITestCase):
|
||||||
@ -22,3 +30,25 @@ class TestTokenAPI(APITestCase):
|
|||||||
token = Token.objects.get(identifier="test-token")
|
token = Token.objects.get(identifier="test-token")
|
||||||
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)
|
||||||
|
|
||||||
|
def test_token_create_non_expiring(self):
|
||||||
|
"""Test token creation endpoint"""
|
||||||
|
self.user.attributes[USER_ATTRIBUTE_TOKEN_EXPIRING] = False
|
||||||
|
self.user.save()
|
||||||
|
response = self.client.post(
|
||||||
|
reverse("authentik_api:token-list"), {"identifier": "test-token"}
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 201)
|
||||||
|
token = Token.objects.get(identifier="test-token")
|
||||||
|
self.assertEqual(token.user, self.user)
|
||||||
|
self.assertEqual(token.intent, TokenIntents.INTENT_API)
|
||||||
|
self.assertEqual(token.expiring, False)
|
||||||
|
|
||||||
|
def test_token_expire(self):
|
||||||
|
"""Test Token expire task"""
|
||||||
|
token: Token = Token.objects.create(expires=now(), user=get_anonymous_user())
|
||||||
|
key = token.key
|
||||||
|
clean_expired_models.delay().get()
|
||||||
|
token.refresh_from_db()
|
||||||
|
self.assertNotEqual(key, token.key)
|
||||||
|
29
authentik/core/tests/test_users_api.py
Normal file
29
authentik/core/tests/test_users_api.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
"""Test Users API"""
|
||||||
|
from django.urls.base import reverse
|
||||||
|
from rest_framework.test import APITestCase
|
||||||
|
|
||||||
|
from authentik.core.models import User
|
||||||
|
|
||||||
|
|
||||||
|
class TestUsersAPI(APITestCase):
|
||||||
|
"""Test Users API"""
|
||||||
|
|
||||||
|
def setUp(self) -> None:
|
||||||
|
self.admin = User.objects.get(username="akadmin")
|
||||||
|
self.user = User.objects.create(username="test-user")
|
||||||
|
|
||||||
|
def test_metrics(self):
|
||||||
|
"""Test user's metrics"""
|
||||||
|
self.client.force_login(self.admin)
|
||||||
|
response = self.client.get(
|
||||||
|
reverse("authentik_api:user-metrics", kwargs={"pk": self.user.pk})
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_metrics_denied(self):
|
||||||
|
"""Test user's metrics (non-superuser)"""
|
||||||
|
self.client.force_login(self.user)
|
||||||
|
response = self.client.get(
|
||||||
|
reverse("authentik_api:user-metrics", kwargs={"pk": self.user.pk})
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 403)
|
@ -2,7 +2,7 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from rest_framework.fields import CharField, DictField
|
from rest_framework.fields import CharField
|
||||||
|
|
||||||
from authentik.core.api.utils import PassiveSerializer
|
from authentik.core.api.utils import PassiveSerializer
|
||||||
from authentik.flows.challenge import Challenge
|
from authentik.flows.challenge import Challenge
|
||||||
@ -22,17 +22,10 @@ class UILoginButton:
|
|||||||
icon_url: Optional[str] = None
|
icon_url: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
class UILoginButtonSerializer(PassiveSerializer):
|
|
||||||
"""Serializer for Login buttons of sources"""
|
|
||||||
|
|
||||||
name = CharField()
|
|
||||||
challenge = DictField()
|
|
||||||
icon_url = CharField(required=False, allow_null=True)
|
|
||||||
|
|
||||||
|
|
||||||
class UserSettingSerializer(PassiveSerializer):
|
class UserSettingSerializer(PassiveSerializer):
|
||||||
"""Serializer for User settings for stages and sources"""
|
"""Serializer for User settings for stages and sources"""
|
||||||
|
|
||||||
object_uid = CharField()
|
object_uid = CharField()
|
||||||
component = CharField()
|
component = CharField()
|
||||||
title = CharField()
|
title = CharField()
|
||||||
|
configure_url = CharField(required=False)
|
||||||
|
@ -6,6 +6,8 @@ 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 impersonate
|
||||||
|
from authentik.core.views.interface import FlowInterfaceView
|
||||||
|
from authentik.core.views.session import EndSessionView
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path(
|
path(
|
||||||
@ -32,7 +34,18 @@ urlpatterns = [
|
|||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"if/flow/<slug:flow_slug>/",
|
"if/flow/<slug:flow_slug>/",
|
||||||
ensure_csrf_cookie(TemplateView.as_view(template_name="if/flow.html")),
|
ensure_csrf_cookie(FlowInterfaceView.as_view()),
|
||||||
name="if-flow",
|
name="if-flow",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"if/session-end/<slug:application_slug>/",
|
||||||
|
ensure_csrf_cookie(EndSessionView.as_view()),
|
||||||
|
name="if-session-end",
|
||||||
|
),
|
||||||
|
# Fallback for WS
|
||||||
|
path("ws/outpost/<uuid:pk>/", TemplateView.as_view(template_name="if/admin.html")),
|
||||||
|
path(
|
||||||
|
"ws/client/",
|
||||||
|
TemplateView.as_view(template_name="if/admin.html"),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
17
authentik/core/views/interface.py
Normal file
17
authentik/core/views/interface.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
"""Interface views"""
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
from django.views.generic.base import TemplateView
|
||||||
|
|
||||||
|
from authentik.flows.models import Flow
|
||||||
|
|
||||||
|
|
||||||
|
class FlowInterfaceView(TemplateView):
|
||||||
|
"""Flow interface"""
|
||||||
|
|
||||||
|
template_name = "if/flow.html"
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
|
||||||
|
kwargs["flow"] = get_object_or_404(Flow, slug=self.kwargs.get("flow_slug"))
|
||||||
|
return super().get_context_data(**kwargs)
|
@ -1,22 +1,24 @@
|
|||||||
"""authentik OAuth2 Session Views"""
|
"""authentik Session Views"""
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.views.generic.base import TemplateView
|
from django.views.generic.base import TemplateView
|
||||||
|
|
||||||
from authentik.core.models import Application
|
from authentik.core.models import Application
|
||||||
|
from authentik.policies.views import PolicyAccessView
|
||||||
|
|
||||||
|
|
||||||
class EndSessionView(TemplateView):
|
class EndSessionView(TemplateView, PolicyAccessView):
|
||||||
"""Allow the client to end the Session"""
|
"""Allow the client to end the Session"""
|
||||||
|
|
||||||
template_name = "providers/oauth2/end_session.html"
|
template_name = "if/end_session.html"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
|
def resolve_provider_application(self):
|
||||||
context = super().get_context_data(**kwargs)
|
self.application = get_object_or_404(
|
||||||
|
|
||||||
context["application"] = get_object_or_404(
|
|
||||||
Application, slug=self.kwargs["application_slug"]
|
Application, slug=self.kwargs["application_slug"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
context["application"] = self.application
|
||||||
return context
|
return context
|
@ -1,12 +1,14 @@
|
|||||||
"""Crypto API Views"""
|
"""Crypto API Views"""
|
||||||
import django_filters
|
|
||||||
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
|
||||||
from django.http.response import HttpResponse
|
from django.http.response import HttpResponse
|
||||||
|
from django.urls import reverse
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from drf_yasg import openapi
|
from django_filters import FilterSet
|
||||||
from drf_yasg.utils import swagger_auto_schema
|
from django_filters.filters import BooleanFilter
|
||||||
|
from drf_spectacular.types import OpenApiTypes
|
||||||
|
from drf_spectacular.utils import OpenApiParameter, OpenApiResponse, extend_schema
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.fields import (
|
from rest_framework.fields import (
|
||||||
CharField,
|
CharField,
|
||||||
@ -20,6 +22,7 @@ from rest_framework.serializers import ModelSerializer, ValidationError
|
|||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
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.utils import PassiveSerializer
|
from authentik.core.api.utils import PassiveSerializer
|
||||||
from authentik.crypto.builder import CertificateBuilder
|
from authentik.crypto.builder import CertificateBuilder
|
||||||
from authentik.crypto.models import CertificateKeyPair
|
from authentik.crypto.models import CertificateKeyPair
|
||||||
@ -33,6 +36,9 @@ class CertificateKeyPairSerializer(ModelSerializer):
|
|||||||
cert_subject = SerializerMethodField()
|
cert_subject = SerializerMethodField()
|
||||||
private_key_available = SerializerMethodField()
|
private_key_available = SerializerMethodField()
|
||||||
|
|
||||||
|
certificate_download_url = SerializerMethodField()
|
||||||
|
private_key_download_url = SerializerMethodField()
|
||||||
|
|
||||||
def get_cert_subject(self, instance: CertificateKeyPair) -> str:
|
def get_cert_subject(self, instance: CertificateKeyPair) -> str:
|
||||||
"""Get certificate subject as full rfc4514"""
|
"""Get certificate subject as full rfc4514"""
|
||||||
return instance.certificate.subject.rfc4514_string()
|
return instance.certificate.subject.rfc4514_string()
|
||||||
@ -41,6 +47,26 @@ 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_certificate_download_url(self, instance: CertificateKeyPair) -> str:
|
||||||
|
"""Get URL to download certificate"""
|
||||||
|
return (
|
||||||
|
reverse(
|
||||||
|
"authentik_api:certificatekeypair-view-certificate",
|
||||||
|
kwargs={"pk": instance.pk},
|
||||||
|
)
|
||||||
|
+ "?download"
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_private_key_download_url(self, instance: CertificateKeyPair) -> str:
|
||||||
|
"""Get URL to download private key"""
|
||||||
|
return (
|
||||||
|
reverse(
|
||||||
|
"authentik_api:certificatekeypair-view-private-key",
|
||||||
|
kwargs={"pk": instance.pk},
|
||||||
|
)
|
||||||
|
+ "?download"
|
||||||
|
)
|
||||||
|
|
||||||
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:
|
||||||
@ -71,12 +97,15 @@ class CertificateKeyPairSerializer(ModelSerializer):
|
|||||||
fields = [
|
fields = [
|
||||||
"pk",
|
"pk",
|
||||||
"name",
|
"name",
|
||||||
"fingerprint",
|
"fingerprint_sha256",
|
||||||
|
"fingerprint_sha1",
|
||||||
"certificate_data",
|
"certificate_data",
|
||||||
"key_data",
|
"key_data",
|
||||||
"cert_expiry",
|
"cert_expiry",
|
||||||
"cert_subject",
|
"cert_subject",
|
||||||
"private_key_available",
|
"private_key_available",
|
||||||
|
"certificate_download_url",
|
||||||
|
"private_key_download_url",
|
||||||
]
|
]
|
||||||
extra_kwargs = {
|
extra_kwargs = {
|
||||||
"key_data": {"write_only": True},
|
"key_data": {"write_only": True},
|
||||||
@ -100,10 +129,10 @@ class CertificateGenerationSerializer(PassiveSerializer):
|
|||||||
validity_days = IntegerField(initial=365)
|
validity_days = IntegerField(initial=365)
|
||||||
|
|
||||||
|
|
||||||
class CertificateKeyPairFilter(django_filters.FilterSet):
|
class CertificateKeyPairFilter(FilterSet):
|
||||||
"""Filter for certificates"""
|
"""Filter for certificates"""
|
||||||
|
|
||||||
has_key = django_filters.BooleanFilter(
|
has_key = BooleanFilter(
|
||||||
label="Only return certificate-key pairs with keys", method="filter_has_key"
|
label="Only return certificate-key pairs with keys", method="filter_has_key"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -117,7 +146,7 @@ class CertificateKeyPairFilter(django_filters.FilterSet):
|
|||||||
fields = ["name"]
|
fields = ["name"]
|
||||||
|
|
||||||
|
|
||||||
class CertificateKeyPairViewSet(ModelViewSet):
|
class CertificateKeyPairViewSet(UsedByMixin, ModelViewSet):
|
||||||
"""CertificateKeyPair Viewset"""
|
"""CertificateKeyPair Viewset"""
|
||||||
|
|
||||||
queryset = CertificateKeyPair.objects.all()
|
queryset = CertificateKeyPair.objects.all()
|
||||||
@ -125,9 +154,12 @@ class CertificateKeyPairViewSet(ModelViewSet):
|
|||||||
filterset_class = CertificateKeyPairFilter
|
filterset_class = CertificateKeyPairFilter
|
||||||
|
|
||||||
@permission_required(None, ["authentik_crypto.add_certificatekeypair"])
|
@permission_required(None, ["authentik_crypto.add_certificatekeypair"])
|
||||||
@swagger_auto_schema(
|
@extend_schema(
|
||||||
request_body=CertificateGenerationSerializer(),
|
request=CertificateGenerationSerializer(),
|
||||||
responses={200: CertificateKeyPairSerializer, 400: "Bad request"},
|
responses={
|
||||||
|
200: CertificateKeyPairSerializer,
|
||||||
|
400: OpenApiResponse(description="Bad request"),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
@action(detail=False, methods=["POST"])
|
@action(detail=False, methods=["POST"])
|
||||||
def generate(self, request: Request) -> Response:
|
def generate(self, request: Request) -> Response:
|
||||||
@ -147,12 +179,12 @@ class CertificateKeyPairViewSet(ModelViewSet):
|
|||||||
serializer = self.get_serializer(instance)
|
serializer = self.get_serializer(instance)
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
@swagger_auto_schema(
|
@extend_schema(
|
||||||
manual_parameters=[
|
parameters=[
|
||||||
openapi.Parameter(
|
OpenApiParameter(
|
||||||
name="download",
|
name="download",
|
||||||
in_=openapi.IN_QUERY,
|
location=OpenApiParameter.QUERY,
|
||||||
type=openapi.TYPE_BOOLEAN,
|
type=OpenApiTypes.BOOL,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
responses={200: CertificateDataSerializer(many=False)},
|
responses={200: CertificateDataSerializer(many=False)},
|
||||||
@ -180,12 +212,12 @@ class CertificateKeyPairViewSet(ModelViewSet):
|
|||||||
CertificateDataSerializer({"data": certificate.certificate_data}).data
|
CertificateDataSerializer({"data": certificate.certificate_data}).data
|
||||||
)
|
)
|
||||||
|
|
||||||
@swagger_auto_schema(
|
@extend_schema(
|
||||||
manual_parameters=[
|
parameters=[
|
||||||
openapi.Parameter(
|
OpenApiParameter(
|
||||||
name="download",
|
name="download",
|
||||||
in_=openapi.IN_QUERY,
|
location=OpenApiParameter.QUERY,
|
||||||
type=openapi.TYPE_BOOLEAN,
|
type=OpenApiTypes.BOOL,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
responses={200: CertificateDataSerializer(many=False)},
|
responses={200: CertificateDataSerializer(many=False)},
|
||||||
|
@ -16,11 +16,6 @@ from authentik.crypto.models import CertificateKeyPair
|
|||||||
class CertificateBuilder:
|
class CertificateBuilder:
|
||||||
"""Build self-signed certificates"""
|
"""Build self-signed certificates"""
|
||||||
|
|
||||||
__public_key = None
|
|
||||||
__private_key = None
|
|
||||||
__builder = None
|
|
||||||
__certificate = None
|
|
||||||
|
|
||||||
common_name: str
|
common_name: str
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -55,20 +55,32 @@ class CertificateKeyPair(CreatedUpdatedModel):
|
|||||||
def private_key(self) -> Optional[RSAPrivateKey]:
|
def private_key(self) -> Optional[RSAPrivateKey]:
|
||||||
"""Get python cryptography PrivateKey instance"""
|
"""Get python cryptography PrivateKey instance"""
|
||||||
if not self._private_key and self._private_key != "":
|
if not self._private_key and self._private_key != "":
|
||||||
|
try:
|
||||||
self._private_key = load_pem_private_key(
|
self._private_key = load_pem_private_key(
|
||||||
str.encode("\n".join([x.strip() for x in self.key_data.split("\n")])),
|
str.encode(
|
||||||
|
"\n".join([x.strip() for x in self.key_data.split("\n")])
|
||||||
|
),
|
||||||
password=None,
|
password=None,
|
||||||
backend=default_backend(),
|
backend=default_backend(),
|
||||||
)
|
)
|
||||||
|
except ValueError:
|
||||||
|
return None
|
||||||
return self._private_key
|
return self._private_key
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fingerprint(self) -> str:
|
def fingerprint_sha256(self) -> str:
|
||||||
"""Get SHA256 Fingerprint of certificate_data"""
|
"""Get SHA256 Fingerprint of certificate_data"""
|
||||||
return hexlify(self.certificate.fingerprint(hashes.SHA256()), ":").decode(
|
return hexlify(self.certificate.fingerprint(hashes.SHA256()), ":").decode(
|
||||||
"utf-8"
|
"utf-8"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def fingerprint_sha1(self) -> str:
|
||||||
|
"""Get SHA1 Fingerprint of certificate_data"""
|
||||||
|
return hexlify(
|
||||||
|
self.certificate.fingerprint(hashes.SHA1()), ":" # nosec
|
||||||
|
).decode("utf-8")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def kid(self):
|
def kid(self):
|
||||||
"""Get Key ID used for JWKS"""
|
"""Get Key ID used for JWKS"""
|
||||||
|
@ -4,10 +4,14 @@ import datetime
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from authentik.core.api.used_by import DeleteAction
|
||||||
from authentik.core.models import User
|
from authentik.core.models import User
|
||||||
from authentik.crypto.api import CertificateKeyPairSerializer
|
from authentik.crypto.api import CertificateKeyPairSerializer
|
||||||
from authentik.crypto.builder import CertificateBuilder
|
from authentik.crypto.builder import CertificateBuilder
|
||||||
from authentik.crypto.models import CertificateKeyPair
|
from authentik.crypto.models import CertificateKeyPair
|
||||||
|
from authentik.flows.models import Flow
|
||||||
|
from authentik.providers.oauth2.generators import generate_client_secret
|
||||||
|
from authentik.providers.oauth2.models import OAuth2Provider
|
||||||
|
|
||||||
|
|
||||||
class TestCrypto(TestCase):
|
class TestCrypto(TestCase):
|
||||||
@ -91,3 +95,35 @@ class TestCrypto(TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(200, response.status_code)
|
self.assertEqual(200, response.status_code)
|
||||||
self.assertIn("Content-Disposition", response)
|
self.assertIn("Content-Disposition", response)
|
||||||
|
|
||||||
|
def test_used_by(self):
|
||||||
|
"""Test used_by endpoint"""
|
||||||
|
self.client.force_login(User.objects.get(username="akadmin"))
|
||||||
|
keypair = CertificateKeyPair.objects.first()
|
||||||
|
provider = OAuth2Provider.objects.create(
|
||||||
|
name="test",
|
||||||
|
client_id="test",
|
||||||
|
client_secret=generate_client_secret(),
|
||||||
|
authorization_flow=Flow.objects.first(),
|
||||||
|
redirect_uris="http://localhost",
|
||||||
|
rsa_key=CertificateKeyPair.objects.first(),
|
||||||
|
)
|
||||||
|
response = self.client.get(
|
||||||
|
reverse(
|
||||||
|
"authentik_api:certificatekeypair-used-by",
|
||||||
|
kwargs={"pk": keypair.pk},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.assertEqual(200, response.status_code)
|
||||||
|
self.assertJSONEqual(
|
||||||
|
response.content.decode(),
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"app": "authentik_providers_oauth2",
|
||||||
|
"model_name": "oauth2provider",
|
||||||
|
"pk": str(provider.pk),
|
||||||
|
"name": str(provider),
|
||||||
|
"action": DeleteAction.SET_NULL.name,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
|
@ -2,14 +2,15 @@
|
|||||||
import django_filters
|
import django_filters
|
||||||
from django.db.models.aggregates import Count
|
from django.db.models.aggregates import Count
|
||||||
from django.db.models.fields.json import KeyTextTransform
|
from django.db.models.fields.json import KeyTextTransform
|
||||||
from drf_yasg.utils import swagger_auto_schema
|
from drf_spectacular.types import OpenApiTypes
|
||||||
|
from drf_spectacular.utils import OpenApiParameter, 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 CharField, DictField, IntegerField
|
from rest_framework.fields import DictField, IntegerField
|
||||||
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 ModelSerializer
|
from rest_framework.serializers import ModelSerializer
|
||||||
from rest_framework.viewsets import ReadOnlyModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.core.api.utils import PassiveSerializer, TypeCreateSerializer
|
from authentik.core.api.utils import PassiveSerializer, TypeCreateSerializer
|
||||||
from authentik.events.models import Event, EventAction
|
from authentik.events.models import Event, EventAction
|
||||||
@ -18,11 +19,6 @@ from authentik.events.models import Event, EventAction
|
|||||||
class EventSerializer(ModelSerializer):
|
class EventSerializer(ModelSerializer):
|
||||||
"""Event Serializer"""
|
"""Event Serializer"""
|
||||||
|
|
||||||
# Since we only use this serializer for read-only operations,
|
|
||||||
# no checking of the action is done here.
|
|
||||||
# This allows clients to check wildcards, prefixes and custom types
|
|
||||||
action = CharField()
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
||||||
model = Event
|
model = Event
|
||||||
@ -35,15 +31,10 @@ class EventSerializer(ModelSerializer):
|
|||||||
"client_ip",
|
"client_ip",
|
||||||
"created",
|
"created",
|
||||||
"expires",
|
"expires",
|
||||||
|
"tenant",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class EventTopPerUserParams(PassiveSerializer):
|
|
||||||
"""Query params for top_per_user"""
|
|
||||||
|
|
||||||
top_n = IntegerField(default=15)
|
|
||||||
|
|
||||||
|
|
||||||
class EventTopPerUserSerializer(PassiveSerializer):
|
class EventTopPerUserSerializer(PassiveSerializer):
|
||||||
"""Response object of Event's top_per_user"""
|
"""Response object of Event's top_per_user"""
|
||||||
|
|
||||||
@ -81,6 +72,11 @@ class EventsFilter(django_filters.FilterSet):
|
|||||||
field_name="action",
|
field_name="action",
|
||||||
lookup_expr="icontains",
|
lookup_expr="icontains",
|
||||||
)
|
)
|
||||||
|
tenant_name = django_filters.CharFilter(
|
||||||
|
field_name="tenant",
|
||||||
|
lookup_expr="name",
|
||||||
|
label="Tenant name",
|
||||||
|
)
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def filter_context_model_pk(self, queryset, name, value):
|
def filter_context_model_pk(self, queryset, name, value):
|
||||||
@ -95,7 +91,7 @@ class EventsFilter(django_filters.FilterSet):
|
|||||||
fields = ["action", "client_ip", "username"]
|
fields = ["action", "client_ip", "username"]
|
||||||
|
|
||||||
|
|
||||||
class EventViewSet(ReadOnlyModelViewSet):
|
class EventViewSet(ModelViewSet):
|
||||||
"""Event Read-Only Viewset"""
|
"""Event Read-Only Viewset"""
|
||||||
|
|
||||||
queryset = Event.objects.all()
|
queryset = Event.objects.all()
|
||||||
@ -111,12 +107,19 @@ class EventViewSet(ReadOnlyModelViewSet):
|
|||||||
]
|
]
|
||||||
filterset_class = EventsFilter
|
filterset_class = EventsFilter
|
||||||
|
|
||||||
@swagger_auto_schema(
|
@extend_schema(
|
||||||
method="GET",
|
methods=["GET"],
|
||||||
responses={200: EventTopPerUserSerializer(many=True)},
|
responses={200: EventTopPerUserSerializer(many=True)},
|
||||||
query_serializer=EventTopPerUserParams,
|
parameters=[
|
||||||
|
OpenApiParameter(
|
||||||
|
"top_n",
|
||||||
|
type=OpenApiTypes.INT,
|
||||||
|
location=OpenApiParameter.QUERY,
|
||||||
|
required=False,
|
||||||
)
|
)
|
||||||
@action(detail=False, methods=["GET"])
|
],
|
||||||
|
)
|
||||||
|
@action(detail=False, methods=["GET"], pagination_class=None)
|
||||||
def top_per_user(self, request: Request):
|
def top_per_user(self, request: Request):
|
||||||
"""Get the top_n events grouped by user count"""
|
"""Get the top_n events grouped by user count"""
|
||||||
filtered_action = request.query_params.get("action", EventAction.LOGIN)
|
filtered_action = request.query_params.get("action", EventAction.LOGIN)
|
||||||
@ -134,7 +137,7 @@ class EventViewSet(ReadOnlyModelViewSet):
|
|||||||
.order_by("-counted_events")[:top_n]
|
.order_by("-counted_events")[:top_n]
|
||||||
)
|
)
|
||||||
|
|
||||||
@swagger_auto_schema(responses={200: TypeCreateSerializer(many=True)})
|
@extend_schema(responses={200: TypeCreateSerializer(many=True)})
|
||||||
@action(detail=False, pagination_class=None, filter_backends=[])
|
@action(detail=False, pagination_class=None, filter_backends=[])
|
||||||
def actions(self, request: Request) -> Response:
|
def actions(self, request: Request) -> Response:
|
||||||
"""Get all actions"""
|
"""Get all actions"""
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
"""Notification API Views"""
|
"""Notification API Views"""
|
||||||
from django_filters.rest_framework import DjangoFilterBackend
|
from django_filters.rest_framework import DjangoFilterBackend
|
||||||
from guardian.utils import get_anonymous_user
|
|
||||||
from rest_framework import mixins
|
from rest_framework import mixins
|
||||||
from rest_framework.fields import ReadOnlyField
|
from rest_framework.fields import ReadOnlyField
|
||||||
from rest_framework.filters import OrderingFilter, SearchFilter
|
from rest_framework.filters import OrderingFilter, SearchFilter
|
||||||
from rest_framework.serializers import ModelSerializer
|
from rest_framework.serializers import ModelSerializer
|
||||||
from rest_framework.viewsets import GenericViewSet
|
from rest_framework.viewsets import GenericViewSet
|
||||||
|
|
||||||
|
from authentik.api.authorization import OwnerFilter, OwnerPermissions
|
||||||
|
from authentik.core.api.used_by import UsedByMixin
|
||||||
from authentik.events.api.event import EventSerializer
|
from authentik.events.api.event import EventSerializer
|
||||||
from authentik.events.models import Notification
|
from authentik.events.models import Notification
|
||||||
|
|
||||||
@ -35,6 +36,7 @@ class NotificationViewSet(
|
|||||||
mixins.RetrieveModelMixin,
|
mixins.RetrieveModelMixin,
|
||||||
mixins.UpdateModelMixin,
|
mixins.UpdateModelMixin,
|
||||||
mixins.DestroyModelMixin,
|
mixins.DestroyModelMixin,
|
||||||
|
UsedByMixin,
|
||||||
mixins.ListModelMixin,
|
mixins.ListModelMixin,
|
||||||
GenericViewSet,
|
GenericViewSet,
|
||||||
):
|
):
|
||||||
@ -49,12 +51,5 @@ class NotificationViewSet(
|
|||||||
"event",
|
"event",
|
||||||
"seen",
|
"seen",
|
||||||
]
|
]
|
||||||
filter_backends = [
|
permission_classes = [OwnerPermissions]
|
||||||
DjangoFilterBackend,
|
filter_backends = [OwnerFilter, DjangoFilterBackend, OrderingFilter, SearchFilter]
|
||||||
OrderingFilter,
|
|
||||||
SearchFilter,
|
|
||||||
]
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
user = self.request.user if self.request else get_anonymous_user()
|
|
||||||
return Notification.objects.filter(user=user.pk)
|
|
||||||
|
@ -3,6 +3,7 @@ from rest_framework.serializers import ModelSerializer
|
|||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.core.api.groups import GroupSerializer
|
from authentik.core.api.groups import GroupSerializer
|
||||||
|
from authentik.core.api.used_by import UsedByMixin
|
||||||
from authentik.events.models import NotificationRule
|
from authentik.events.models import NotificationRule
|
||||||
|
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ class NotificationRuleSerializer(ModelSerializer):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class NotificationRuleViewSet(ModelViewSet):
|
class NotificationRuleViewSet(UsedByMixin, ModelViewSet):
|
||||||
"""NotificationRule Viewset"""
|
"""NotificationRule Viewset"""
|
||||||
|
|
||||||
queryset = NotificationRule.objects.all()
|
queryset = NotificationRule.objects.all()
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
"""NotificationTransport API Views"""
|
"""NotificationTransport API Views"""
|
||||||
from drf_yasg.utils import no_body, swagger_auto_schema
|
from drf_spectacular.types import OpenApiTypes
|
||||||
|
from drf_spectacular.utils import OpenApiResponse, extend_schema
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.fields import CharField, ListField, SerializerMethodField
|
from rest_framework.fields import CharField, ListField, SerializerMethodField
|
||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
@ -8,6 +9,7 @@ from rest_framework.serializers import ModelSerializer, Serializer
|
|||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.api.decorators import permission_required
|
from authentik.api.decorators import permission_required
|
||||||
|
from authentik.core.api.used_by import UsedByMixin
|
||||||
from authentik.events.models import (
|
from authentik.events.models import (
|
||||||
Notification,
|
Notification,
|
||||||
NotificationSeverity,
|
NotificationSeverity,
|
||||||
@ -22,7 +24,7 @@ class NotificationTransportSerializer(ModelSerializer):
|
|||||||
|
|
||||||
mode_verbose = SerializerMethodField()
|
mode_verbose = SerializerMethodField()
|
||||||
|
|
||||||
def get_mode_verbose(self, instance: NotificationTransport):
|
def get_mode_verbose(self, instance: NotificationTransport) -> str:
|
||||||
"""Return selected mode with a UI Label"""
|
"""Return selected mode with a UI Label"""
|
||||||
return TransportMode(instance.mode).label
|
return TransportMode(instance.mode).label
|
||||||
|
|
||||||
@ -44,26 +46,26 @@ class NotificationTransportTestSerializer(Serializer):
|
|||||||
|
|
||||||
messages = ListField(child=CharField())
|
messages = ListField(child=CharField())
|
||||||
|
|
||||||
def create(self, request: Request) -> Response:
|
def create(self, validated_data: Request) -> Response:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def update(self, request: Request) -> Response:
|
def update(self, request: Request) -> Response:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class NotificationTransportViewSet(ModelViewSet):
|
class NotificationTransportViewSet(UsedByMixin, ModelViewSet):
|
||||||
"""NotificationTransport Viewset"""
|
"""NotificationTransport Viewset"""
|
||||||
|
|
||||||
queryset = NotificationTransport.objects.all()
|
queryset = NotificationTransport.objects.all()
|
||||||
serializer_class = NotificationTransportSerializer
|
serializer_class = NotificationTransportSerializer
|
||||||
|
|
||||||
@permission_required("authentik_events.change_notificationtransport")
|
@permission_required("authentik_events.change_notificationtransport")
|
||||||
@swagger_auto_schema(
|
@extend_schema(
|
||||||
responses={
|
responses={
|
||||||
200: NotificationTransportTestSerializer(many=False),
|
200: NotificationTransportTestSerializer(many=False),
|
||||||
503: "Failed to test transport",
|
500: OpenApiResponse(description="Failed to test transport"),
|
||||||
},
|
},
|
||||||
request_body=no_body,
|
request=OpenApiTypes.NONE,
|
||||||
)
|
)
|
||||||
@action(detail=True, pagination_class=None, filter_backends=[], methods=["post"])
|
@action(detail=True, pagination_class=None, filter_backends=[], methods=["post"])
|
||||||
# pylint: disable=invalid-name, unused-argument
|
# pylint: disable=invalid-name, unused-argument
|
||||||
@ -83,4 +85,4 @@ class NotificationTransportViewSet(ModelViewSet):
|
|||||||
response.is_valid()
|
response.is_valid()
|
||||||
return Response(response.data)
|
return Response(response.data)
|
||||||
except NotificationTransportError as exc:
|
except NotificationTransportError as exc:
|
||||||
return Response(str(exc.__cause__ or None), status=503)
|
return Response(str(exc.__cause__ or None), status=500)
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
"""authentik events app"""
|
"""authentik events app"""
|
||||||
|
from datetime import timedelta
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
from django.db import ProgrammingError
|
||||||
|
from django.utils.timezone import now
|
||||||
|
|
||||||
|
|
||||||
class AuthentikEventsConfig(AppConfig):
|
class AuthentikEventsConfig(AppConfig):
|
||||||
@ -13,3 +16,12 @@ class AuthentikEventsConfig(AppConfig):
|
|||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
import_module("authentik.events.signals")
|
import_module("authentik.events.signals")
|
||||||
|
try:
|
||||||
|
from authentik.events.models import Event
|
||||||
|
|
||||||
|
date_from = now() - timedelta(days=1)
|
||||||
|
|
||||||
|
for event in Event.objects.filter(created__gte=date_from):
|
||||||
|
event._set_prom_metrics()
|
||||||
|
except ProgrammingError:
|
||||||
|
pass
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
"""events GeoIP Reader"""
|
"""events GeoIP Reader"""
|
||||||
from typing import Optional
|
from datetime import datetime
|
||||||
|
from os import stat
|
||||||
|
from time import time
|
||||||
|
from typing import Optional, TypedDict
|
||||||
|
|
||||||
from geoip2.database import Reader
|
from geoip2.database import Reader
|
||||||
|
from geoip2.errors import GeoIP2Error
|
||||||
|
from geoip2.models import City
|
||||||
from structlog.stdlib import get_logger
|
from structlog.stdlib import get_logger
|
||||||
|
|
||||||
from authentik.lib.config import CONFIG
|
from authentik.lib.config import CONFIG
|
||||||
@ -9,17 +14,77 @@ from authentik.lib.config import CONFIG
|
|||||||
LOGGER = get_logger()
|
LOGGER = get_logger()
|
||||||
|
|
||||||
|
|
||||||
def get_geoip_reader() -> Optional[Reader]:
|
class GeoIPDict(TypedDict):
|
||||||
|
"""GeoIP Details"""
|
||||||
|
|
||||||
|
continent: str
|
||||||
|
country: str
|
||||||
|
lat: float
|
||||||
|
long: float
|
||||||
|
city: str
|
||||||
|
|
||||||
|
|
||||||
|
class GeoIPReader:
|
||||||
|
"""Slim wrapper around GeoIP API"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.__reader: Optional[Reader] = None
|
||||||
|
self.__last_mtime: float = 0.0
|
||||||
|
self.__open()
|
||||||
|
|
||||||
|
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("authentik.geoip")
|
||||||
if path == "" or not path:
|
if path == "" or not path:
|
||||||
return None
|
return
|
||||||
try:
|
try:
|
||||||
reader = Reader(path)
|
reader = Reader(path)
|
||||||
LOGGER.info("Enabled GeoIP support")
|
self.__reader = reader
|
||||||
return reader
|
self.__last_mtime = stat(path).st_mtime
|
||||||
except OSError:
|
LOGGER.info("Loaded GeoIP database", last_write=self.__last_mtime)
|
||||||
|
except OSError as exc:
|
||||||
|
LOGGER.warning("Failed to load GeoIP database", exc=exc)
|
||||||
|
|
||||||
|
def __check_expired(self):
|
||||||
|
"""Check if the geoip database has been opened longer than 8 hours,
|
||||||
|
and re-open it, as it will probably will have been re-downloaded"""
|
||||||
|
now = time()
|
||||||
|
diff = datetime.fromtimestamp(now) - datetime.fromtimestamp(self.__last_mtime)
|
||||||
|
diff_hours = diff.total_seconds() // 3600
|
||||||
|
if diff_hours >= 8:
|
||||||
|
LOGGER.info("GeoIP databased loaded too long, re-opening", diff=diff)
|
||||||
|
self.__open()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def enabled(self) -> bool:
|
||||||
|
"""Check if GeoIP is enabled"""
|
||||||
|
return bool(self.__reader)
|
||||||
|
|
||||||
|
def city(self, ip_address: str) -> Optional[City]:
|
||||||
|
"""Wrapper for Reader.city"""
|
||||||
|
if not self.enabled:
|
||||||
|
return None
|
||||||
|
self.__check_expired()
|
||||||
|
try:
|
||||||
|
return self.__reader.city(ip_address)
|
||||||
|
except (GeoIP2Error, ValueError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def city_dict(self, ip_address: str) -> Optional[GeoIPDict]:
|
||||||
|
"""Wrapper for self.city that returns a dict"""
|
||||||
|
city = self.city(ip_address)
|
||||||
|
if not city:
|
||||||
|
return None
|
||||||
|
city_dict: GeoIPDict = {
|
||||||
|
"continent": city.continent.code,
|
||||||
|
"country": city.country.iso_code,
|
||||||
|
"lat": city.location.latitude,
|
||||||
|
"long": city.location.longitude,
|
||||||
|
"city": "",
|
||||||
|
}
|
||||||
|
if city.city.name:
|
||||||
|
city_dict["city"] = city.city.name
|
||||||
|
return city_dict
|
||||||
|
|
||||||
GEOIP_READER = get_geoip_reader()
|
|
||||||
|
GEOIP_READER = GeoIPReader()
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.core.exceptions import SuspiciousOperation
|
||||||
from django.db.models import Model
|
from django.db.models import Model
|
||||||
from django.db.models.signals import post_save, pre_delete
|
from django.db.models.signals import post_save, pre_delete
|
||||||
from django.http import HttpRequest, HttpResponse
|
from django.http import HttpRequest, HttpResponse
|
||||||
@ -12,6 +14,8 @@ from authentik.core.models import User
|
|||||||
from authentik.events.models import Event, EventAction, Notification
|
from authentik.events.models import Event, EventAction, Notification
|
||||||
from authentik.events.signals import EventNewThread
|
from authentik.events.signals import EventNewThread
|
||||||
from authentik.events.utils import model_to_dict
|
from authentik.events.utils import model_to_dict
|
||||||
|
from authentik.lib.sentry import before_send
|
||||||
|
from authentik.lib.utils.errors import exception_to_string
|
||||||
|
|
||||||
|
|
||||||
class AuditMiddleware:
|
class AuditMiddleware:
|
||||||
@ -54,10 +58,28 @@ class AuditMiddleware:
|
|||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def process_exception(self, request: HttpRequest, exception: Exception):
|
def process_exception(self, request: HttpRequest, exception: Exception):
|
||||||
"""Unregister handlers in case of exception"""
|
"""Disconnect handlers in case of exception"""
|
||||||
post_save.disconnect(dispatch_uid=LOCAL.authentik["request_id"])
|
post_save.disconnect(dispatch_uid=LOCAL.authentik["request_id"])
|
||||||
pre_delete.disconnect(dispatch_uid=LOCAL.authentik["request_id"])
|
pre_delete.disconnect(dispatch_uid=LOCAL.authentik["request_id"])
|
||||||
|
|
||||||
|
if settings.DEBUG:
|
||||||
|
return
|
||||||
|
# Special case for SuspiciousOperation, we have a special event action for that
|
||||||
|
if isinstance(exception, SuspiciousOperation):
|
||||||
|
thread = EventNewThread(
|
||||||
|
EventAction.SUSPICIOUS_REQUEST,
|
||||||
|
request,
|
||||||
|
message=str(exception),
|
||||||
|
)
|
||||||
|
thread.run()
|
||||||
|
elif before_send({}, {"exc_info": (None, exception, None)}) is not None:
|
||||||
|
thread = EventNewThread(
|
||||||
|
EventAction.SYSTEM_EXCEPTION,
|
||||||
|
request,
|
||||||
|
message=exception_to_string(exception),
|
||||||
|
)
|
||||||
|
thread.run()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def post_save_handler(
|
def post_save_handler(
|
||||||
|
45
authentik/events/migrations/0015_alter_event_action.py
Normal file
45
authentik/events/migrations/0015_alter_event_action.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# Generated by Django 3.2.3 on 2021-06-09 07:58
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("authentik_events", "0014_expiry"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="event",
|
||||||
|
name="action",
|
||||||
|
field=models.TextField(
|
||||||
|
choices=[
|
||||||
|
("login", "Login"),
|
||||||
|
("login_failed", "Login Failed"),
|
||||||
|
("logout", "Logout"),
|
||||||
|
("user_write", "User Write"),
|
||||||
|
("suspicious_request", "Suspicious Request"),
|
||||||
|
("password_set", "Password Set"),
|
||||||
|
("secret_view", "Secret View"),
|
||||||
|
("invitation_used", "Invite Used"),
|
||||||
|
("authorize_application", "Authorize Application"),
|
||||||
|
("source_linked", "Source Linked"),
|
||||||
|
("impersonation_started", "Impersonation Started"),
|
||||||
|
("impersonation_ended", "Impersonation Ended"),
|
||||||
|
("policy_execution", "Policy Execution"),
|
||||||
|
("policy_exception", "Policy Exception"),
|
||||||
|
("property_mapping_exception", "Property Mapping Exception"),
|
||||||
|
("system_task_execution", "System Task Execution"),
|
||||||
|
("system_task_exception", "System Task Exception"),
|
||||||
|
("configuration_error", "Configuration Error"),
|
||||||
|
("model_created", "Model Created"),
|
||||||
|
("model_updated", "Model Updated"),
|
||||||
|
("model_deleted", "Model Deleted"),
|
||||||
|
("email_sent", "Email Sent"),
|
||||||
|
("update_available", "Update Available"),
|
||||||
|
("custom_", "Custom Prefix"),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
55
authentik/events/migrations/0016_add_tenant.py
Normal file
55
authentik/events/migrations/0016_add_tenant.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
# Generated by Django 3.2.4 on 2021-06-14 15:33
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
import authentik.events.models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("authentik_events", "0015_alter_event_action"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="event",
|
||||||
|
name="tenant",
|
||||||
|
field=models.JSONField(
|
||||||
|
blank=True, default=authentik.events.models.default_tenant
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="event",
|
||||||
|
name="action",
|
||||||
|
field=models.TextField(
|
||||||
|
choices=[
|
||||||
|
("login", "Login"),
|
||||||
|
("login_failed", "Login Failed"),
|
||||||
|
("logout", "Logout"),
|
||||||
|
("user_write", "User Write"),
|
||||||
|
("suspicious_request", "Suspicious Request"),
|
||||||
|
("password_set", "Password Set"),
|
||||||
|
("secret_view", "Secret View"),
|
||||||
|
("invitation_used", "Invite Used"),
|
||||||
|
("authorize_application", "Authorize Application"),
|
||||||
|
("source_linked", "Source Linked"),
|
||||||
|
("impersonation_started", "Impersonation Started"),
|
||||||
|
("impersonation_ended", "Impersonation Ended"),
|
||||||
|
("policy_execution", "Policy Execution"),
|
||||||
|
("policy_exception", "Policy Exception"),
|
||||||
|
("property_mapping_exception", "Property Mapping Exception"),
|
||||||
|
("system_task_execution", "System Task Execution"),
|
||||||
|
("system_task_exception", "System Task Exception"),
|
||||||
|
("system_exception", "System Exception"),
|
||||||
|
("configuration_error", "Configuration Error"),
|
||||||
|
("model_created", "Model Created"),
|
||||||
|
("model_updated", "Model Updated"),
|
||||||
|
("model_deleted", "Model Deleted"),
|
||||||
|
("email_sent", "Email Sent"),
|
||||||
|
("update_available", "Update Available"),
|
||||||
|
("custom_", "Custom Prefix"),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
47
authentik/events/migrations/0017_alter_event_action.py
Normal file
47
authentik/events/migrations/0017_alter_event_action.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# Generated by Django 3.2.5 on 2021-07-14 19:15
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("authentik_events", "0016_add_tenant"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="event",
|
||||||
|
name="action",
|
||||||
|
field=models.TextField(
|
||||||
|
choices=[
|
||||||
|
("login", "Login"),
|
||||||
|
("login_failed", "Login Failed"),
|
||||||
|
("logout", "Logout"),
|
||||||
|
("user_write", "User Write"),
|
||||||
|
("suspicious_request", "Suspicious Request"),
|
||||||
|
("password_set", "Password Set"),
|
||||||
|
("secret_view", "Secret View"),
|
||||||
|
("secret_rotate", "Secret Rotate"),
|
||||||
|
("invitation_used", "Invite Used"),
|
||||||
|
("authorize_application", "Authorize Application"),
|
||||||
|
("source_linked", "Source Linked"),
|
||||||
|
("impersonation_started", "Impersonation Started"),
|
||||||
|
("impersonation_ended", "Impersonation Ended"),
|
||||||
|
("policy_execution", "Policy Execution"),
|
||||||
|
("policy_exception", "Policy Exception"),
|
||||||
|
("property_mapping_exception", "Property Mapping Exception"),
|
||||||
|
("system_task_execution", "System Task Execution"),
|
||||||
|
("system_task_exception", "System Task Exception"),
|
||||||
|
("system_exception", "System Exception"),
|
||||||
|
("configuration_error", "Configuration Error"),
|
||||||
|
("model_created", "Model Created"),
|
||||||
|
("model_updated", "Model Updated"),
|
||||||
|
("model_deleted", "Model Deleted"),
|
||||||
|
("email_sent", "Email Sent"),
|
||||||
|
("update_available", "Update Available"),
|
||||||
|
("custom_", "Custom Prefix"),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
@ -10,7 +10,7 @@ from django.db import models
|
|||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
from geoip2.errors import GeoIP2Error
|
from prometheus_client import Gauge
|
||||||
from requests import RequestException, post
|
from requests import RequestException, post
|
||||||
from structlog.stdlib import get_logger
|
from structlog.stdlib import get_logger
|
||||||
|
|
||||||
@ -21,20 +21,34 @@ from authentik.core.middleware import (
|
|||||||
)
|
)
|
||||||
from authentik.core.models import ExpiringModel, Group, User
|
from authentik.core.models import ExpiringModel, Group, User
|
||||||
from authentik.events.geo import GEOIP_READER
|
from authentik.events.geo import GEOIP_READER
|
||||||
from authentik.events.utils import cleanse_dict, get_user, sanitize_dict
|
from authentik.events.utils import cleanse_dict, get_user, model_to_dict, sanitize_dict
|
||||||
from authentik.lib.sentry import SentryIgnoredException
|
from authentik.lib.sentry import SentryIgnoredException
|
||||||
from authentik.lib.utils.http import get_client_ip
|
from authentik.lib.utils.http import get_client_ip
|
||||||
|
from authentik.lib.utils.time import timedelta_from_string
|
||||||
from authentik.policies.models import PolicyBindingModel
|
from authentik.policies.models import PolicyBindingModel
|
||||||
from authentik.stages.email.utils import TemplateEmailMessage
|
from authentik.stages.email.utils import TemplateEmailMessage
|
||||||
|
from authentik.tenants.models import Tenant
|
||||||
|
from authentik.tenants.utils import DEFAULT_TENANT
|
||||||
|
|
||||||
LOGGER = get_logger("authentik.events")
|
LOGGER = get_logger("authentik.events")
|
||||||
|
GAUGE_EVENTS = Gauge(
|
||||||
|
"authentik_events",
|
||||||
|
"Events in authentik",
|
||||||
|
["action", "user_username", "app", "client_ip"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def default_event_duration():
|
def default_event_duration():
|
||||||
"""Default duration an Event is saved"""
|
"""Default duration an Event is saved.
|
||||||
|
This is used as a fallback when no tenant is available"""
|
||||||
return now() + timedelta(days=365)
|
return now() + timedelta(days=365)
|
||||||
|
|
||||||
|
|
||||||
|
def default_tenant():
|
||||||
|
"""Get a default value for tenant"""
|
||||||
|
return sanitize_dict(model_to_dict(DEFAULT_TENANT))
|
||||||
|
|
||||||
|
|
||||||
class NotificationTransportError(SentryIgnoredException):
|
class NotificationTransportError(SentryIgnoredException):
|
||||||
"""Error raised when a notification fails to be delivered"""
|
"""Error raised when a notification fails to be delivered"""
|
||||||
|
|
||||||
@ -51,6 +65,7 @@ class EventAction(models.TextChoices):
|
|||||||
PASSWORD_SET = "password_set" # noqa # nosec
|
PASSWORD_SET = "password_set" # noqa # nosec
|
||||||
|
|
||||||
SECRET_VIEW = "secret_view" # noqa # nosec
|
SECRET_VIEW = "secret_view" # noqa # nosec
|
||||||
|
SECRET_ROTATE = "secret_rotate" # noqa # nosec
|
||||||
|
|
||||||
INVITE_USED = "invitation_used"
|
INVITE_USED = "invitation_used"
|
||||||
|
|
||||||
@ -66,12 +81,14 @@ class EventAction(models.TextChoices):
|
|||||||
|
|
||||||
SYSTEM_TASK_EXECUTION = "system_task_execution"
|
SYSTEM_TASK_EXECUTION = "system_task_execution"
|
||||||
SYSTEM_TASK_EXCEPTION = "system_task_exception"
|
SYSTEM_TASK_EXCEPTION = "system_task_exception"
|
||||||
|
SYSTEM_EXCEPTION = "system_exception"
|
||||||
|
|
||||||
CONFIGURATION_ERROR = "configuration_error"
|
CONFIGURATION_ERROR = "configuration_error"
|
||||||
|
|
||||||
MODEL_CREATED = "model_created"
|
MODEL_CREATED = "model_created"
|
||||||
MODEL_UPDATED = "model_updated"
|
MODEL_UPDATED = "model_updated"
|
||||||
MODEL_DELETED = "model_deleted"
|
MODEL_DELETED = "model_deleted"
|
||||||
|
EMAIL_SENT = "email_sent"
|
||||||
|
|
||||||
UPDATE_AVAILABLE = "update_available"
|
UPDATE_AVAILABLE = "update_available"
|
||||||
|
|
||||||
@ -88,6 +105,7 @@ class Event(ExpiringModel):
|
|||||||
context = models.JSONField(default=dict, blank=True)
|
context = models.JSONField(default=dict, blank=True)
|
||||||
client_ip = models.GenericIPAddressField(null=True)
|
client_ip = models.GenericIPAddressField(null=True)
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
|
tenant = models.JSONField(default=default_tenant, blank=True)
|
||||||
|
|
||||||
# Shadow the expires attribute from ExpiringModel to override the default duration
|
# Shadow the expires attribute from ExpiringModel to override the default duration
|
||||||
expires = models.DateTimeField(default=default_event_duration)
|
expires = models.DateTimeField(default=default_event_duration)
|
||||||
@ -126,6 +144,18 @@ class Event(ExpiringModel):
|
|||||||
"""Add data from a Django-HttpRequest, allowing the creation of
|
"""Add data from a Django-HttpRequest, allowing the creation of
|
||||||
Events independently from requests.
|
Events independently from requests.
|
||||||
`user` arguments optionally overrides user from requests."""
|
`user` arguments optionally overrides user from requests."""
|
||||||
|
if request:
|
||||||
|
self.context["http_request"] = {
|
||||||
|
"path": request.get_full_path(),
|
||||||
|
"method": request.method,
|
||||||
|
}
|
||||||
|
if hasattr(request, "tenant"):
|
||||||
|
tenant: Tenant = request.tenant
|
||||||
|
# Because self.created only gets set on save, we can't use it's value here
|
||||||
|
# hence we set self.created to now and then use it
|
||||||
|
self.created = now()
|
||||||
|
self.expires = self.created + timedelta_from_string(tenant.event_retention)
|
||||||
|
self.tenant = sanitize_dict(model_to_dict(tenant))
|
||||||
if hasattr(request, "user"):
|
if hasattr(request, "user"):
|
||||||
original_user = None
|
original_user = None
|
||||||
if hasattr(request, "session"):
|
if hasattr(request, "session"):
|
||||||
@ -143,7 +173,7 @@ class Event(ExpiringModel):
|
|||||||
request.session[SESSION_IMPERSONATE_USER]
|
request.session[SESSION_IMPERSONATE_USER]
|
||||||
)
|
)
|
||||||
# User 255.255.255.255 as fallback if IP cannot be determined
|
# User 255.255.255.255 as fallback if IP cannot be determined
|
||||||
self.client_ip = get_client_ip(request) or "255.255.255.255"
|
self.client_ip = get_client_ip(request)
|
||||||
# Apply GeoIP Data, when enabled
|
# Apply GeoIP Data, when enabled
|
||||||
self.with_geoip()
|
self.with_geoip()
|
||||||
# If there's no app set, we get it from the requests too
|
# If there's no app set, we get it from the requests too
|
||||||
@ -152,22 +182,20 @@ class Event(ExpiringModel):
|
|||||||
self.save()
|
self.save()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def with_geoip(self):
|
def with_geoip(self): # pragma: no cover
|
||||||
"""Apply GeoIP Data, when enabled"""
|
"""Apply GeoIP Data, when enabled"""
|
||||||
if not GEOIP_READER:
|
city = GEOIP_READER.city_dict(self.client_ip)
|
||||||
|
if not city:
|
||||||
return
|
return
|
||||||
try:
|
self.context["geo"] = city
|
||||||
response = GEOIP_READER.city(self.client_ip)
|
|
||||||
self.context["geo"] = {
|
def _set_prom_metrics(self):
|
||||||
"continent": response.continent.code,
|
GAUGE_EVENTS.labels(
|
||||||
"country": response.country.iso_code,
|
action=self.action,
|
||||||
"lat": response.location.latitude,
|
user_username=self.user.get("username"),
|
||||||
"long": response.location.longitude,
|
app=self.app,
|
||||||
}
|
client_ip=self.client_ip,
|
||||||
if response.city.name:
|
).set(self.created.timestamp())
|
||||||
self.context["geo"]["city"] = response.city.name
|
|
||||||
except GeoIP2Error as exc:
|
|
||||||
LOGGER.warning("Failed to add geoIP Data to event", exc=exc)
|
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if self._state.adding:
|
if self._state.adding:
|
||||||
@ -178,7 +206,8 @@ class Event(ExpiringModel):
|
|||||||
client_ip=self.client_ip,
|
client_ip=self.client_ip,
|
||||||
user=self.user,
|
user=self.user,
|
||||||
)
|
)
|
||||||
return super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
self._set_prom_metrics()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def summary(self) -> str:
|
def summary(self) -> str:
|
||||||
@ -293,7 +322,8 @@ class NotificationTransport(models.Model):
|
|||||||
response = post(self.webhook_url, json=body)
|
response = post(self.webhook_url, json=body)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except RequestException as exc:
|
except RequestException as exc:
|
||||||
raise NotificationTransportError(exc.response.text) from exc
|
text = exc.response.text if exc.response else str(exc)
|
||||||
|
raise NotificationTransportError(text) from exc
|
||||||
return [
|
return [
|
||||||
response.status_code,
|
response.status_code,
|
||||||
response.text,
|
response.text,
|
||||||
|
@ -2,14 +2,22 @@
|
|||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
from timeit import default_timer
|
||||||
from traceback import format_tb
|
from traceback import format_tb
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
from celery import Task
|
from celery import Task
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
from prometheus_client import Gauge
|
||||||
|
|
||||||
from authentik.events.models import Event, EventAction
|
from authentik.events.models import Event, EventAction
|
||||||
|
|
||||||
|
GAUGE_TASKS = Gauge(
|
||||||
|
"authentik_system_tasks",
|
||||||
|
"System tasks and their status",
|
||||||
|
["task_name", "task_uid", "status"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TaskResultStatus(Enum):
|
class TaskResultStatus(Enum):
|
||||||
"""Possible states of tasks"""
|
"""Possible states of tasks"""
|
||||||
@ -43,7 +51,9 @@ class TaskInfo:
|
|||||||
"""Info about a task run"""
|
"""Info about a task run"""
|
||||||
|
|
||||||
task_name: str
|
task_name: str
|
||||||
finish_timestamp: datetime
|
start_timestamp: float
|
||||||
|
finish_timestamp: float
|
||||||
|
finish_time: datetime
|
||||||
|
|
||||||
result: TaskResult
|
result: TaskResult
|
||||||
|
|
||||||
@ -73,12 +83,28 @@ class TaskInfo:
|
|||||||
"""Delete task info from cache"""
|
"""Delete task info from cache"""
|
||||||
return cache.delete(f"task_{self.task_name}")
|
return cache.delete(f"task_{self.task_name}")
|
||||||
|
|
||||||
|
def set_prom_metrics(self):
|
||||||
|
"""Update prometheus metrics"""
|
||||||
|
start = default_timer()
|
||||||
|
if hasattr(self, "start_timestamp"):
|
||||||
|
start = self.start_timestamp
|
||||||
|
try:
|
||||||
|
duration = max(self.finish_timestamp - start, 0)
|
||||||
|
except TypeError:
|
||||||
|
duration = 0
|
||||||
|
GAUGE_TASKS.labels(
|
||||||
|
task_name=self.task_name,
|
||||||
|
task_uid=self.result.uid or "",
|
||||||
|
status=self.result.status,
|
||||||
|
).set(duration)
|
||||||
|
|
||||||
def save(self, timeout_hours=6):
|
def save(self, timeout_hours=6):
|
||||||
"""Save task into cache"""
|
"""Save task into cache"""
|
||||||
key = f"task_{self.task_name}"
|
key = f"task_{self.task_name}"
|
||||||
if self.result.uid:
|
if self.result.uid:
|
||||||
key += f"_{self.result.uid}"
|
key += f"_{self.result.uid}"
|
||||||
self.task_name += f"_{self.result.uid}"
|
self.task_name += f"_{self.result.uid}"
|
||||||
|
self.set_prom_metrics()
|
||||||
cache.set(key, self, timeout=timeout_hours * 60 * 60)
|
cache.set(key, self, timeout=timeout_hours * 60 * 60)
|
||||||
|
|
||||||
|
|
||||||
@ -88,7 +114,7 @@ class MonitoredTask(Task):
|
|||||||
# For tasks that should only be listed if they failed, set this to False
|
# For tasks that should only be listed if they failed, set this to False
|
||||||
save_on_success: bool
|
save_on_success: bool
|
||||||
|
|
||||||
_result: TaskResult
|
_result: Optional[TaskResult]
|
||||||
|
|
||||||
_uid: Optional[str]
|
_uid: Optional[str]
|
||||||
|
|
||||||
@ -96,8 +122,9 @@ class MonitoredTask(Task):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.save_on_success = True
|
self.save_on_success = True
|
||||||
self._uid = None
|
self._uid = None
|
||||||
self._result = TaskResult(status=TaskResultStatus.ERROR, messages=[])
|
self._result = None
|
||||||
self.result_timeout_hours = 6
|
self.result_timeout_hours = 6
|
||||||
|
self.start = default_timer()
|
||||||
|
|
||||||
def set_uid(self, uid: str):
|
def set_uid(self, uid: str):
|
||||||
"""Set UID, so in the case of an unexpected error its saved correctly"""
|
"""Set UID, so in the case of an unexpected error its saved correctly"""
|
||||||
@ -111,13 +138,16 @@ class MonitoredTask(Task):
|
|||||||
def after_return(
|
def after_return(
|
||||||
self, status, retval, task_id, args: list[Any], kwargs: dict[str, Any], einfo
|
self, status, retval, task_id, args: list[Any], kwargs: dict[str, Any], einfo
|
||||||
):
|
):
|
||||||
|
if self._result:
|
||||||
if not self._result.uid:
|
if not self._result.uid:
|
||||||
self._result.uid = self._uid
|
self._result.uid = self._uid
|
||||||
if self.save_on_success:
|
if self.save_on_success:
|
||||||
TaskInfo(
|
TaskInfo(
|
||||||
task_name=self.__name__,
|
task_name=self.__name__,
|
||||||
task_description=self.__doc__,
|
task_description=self.__doc__,
|
||||||
finish_timestamp=datetime.now(),
|
start_timestamp=self.start,
|
||||||
|
finish_timestamp=default_timer(),
|
||||||
|
finish_time=datetime.now(),
|
||||||
result=self._result,
|
result=self._result,
|
||||||
task_call_module=self.__module__,
|
task_call_module=self.__module__,
|
||||||
task_call_func=self.__name__,
|
task_call_func=self.__name__,
|
||||||
@ -128,12 +158,18 @@ class MonitoredTask(Task):
|
|||||||
|
|
||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments
|
||||||
def on_failure(self, exc, task_id, args, kwargs, einfo):
|
def on_failure(self, exc, task_id, args, kwargs, einfo):
|
||||||
|
if not self._result:
|
||||||
|
self._result = TaskResult(
|
||||||
|
status=TaskResultStatus.ERROR, messages=[str(exc)]
|
||||||
|
)
|
||||||
if not self._result.uid:
|
if not self._result.uid:
|
||||||
self._result.uid = self._uid
|
self._result.uid = self._uid
|
||||||
TaskInfo(
|
TaskInfo(
|
||||||
task_name=self.__name__,
|
task_name=self.__name__,
|
||||||
task_description=self.__doc__,
|
task_description=self.__doc__,
|
||||||
finish_timestamp=datetime.now(),
|
start_timestamp=self.start,
|
||||||
|
finish_timestamp=default_timer(),
|
||||||
|
finish_time=datetime.now(),
|
||||||
result=self._result,
|
result=self._result,
|
||||||
task_call_module=self.__module__,
|
task_call_module=self.__module__,
|
||||||
task_call_func=self.__name__,
|
task_call_func=self.__name__,
|
||||||
@ -151,3 +187,7 @@ class MonitoredTask(Task):
|
|||||||
|
|
||||||
def run(self, *args, **kwargs):
|
def run(self, *args, **kwargs):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
|
for task in TaskInfo.all().values():
|
||||||
|
task.set_prom_metrics()
|
||||||
|
@ -105,7 +105,11 @@ def notification_transport(
|
|||||||
"""Send notification over specified transport"""
|
"""Send notification over specified transport"""
|
||||||
self.save_on_success = False
|
self.save_on_success = False
|
||||||
try:
|
try:
|
||||||
notification: Notification = Notification.objects.get(pk=notification_pk)
|
notification: Notification = Notification.objects.filter(
|
||||||
|
pk=notification_pk
|
||||||
|
).first()
|
||||||
|
if not notification:
|
||||||
|
return
|
||||||
transport: NotificationTransport = NotificationTransport.objects.get(
|
transport: NotificationTransport = NotificationTransport.objects.get(
|
||||||
pk=transport_pk
|
pk=transport_pk
|
||||||
)
|
)
|
||||||
|
26
authentik/events/tests/test_geoip.py
Normal file
26
authentik/events/tests/test_geoip.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
"""Test GeoIP Wrapper"""
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from authentik.events.geo import GeoIPReader
|
||||||
|
|
||||||
|
|
||||||
|
class TestGeoIP(TestCase):
|
||||||
|
"""Test GeoIP Wrapper"""
|
||||||
|
|
||||||
|
def setUp(self) -> None:
|
||||||
|
self.reader = GeoIPReader()
|
||||||
|
|
||||||
|
def test_simple(self):
|
||||||
|
"""Test simple city wrapper"""
|
||||||
|
# IPs from
|
||||||
|
# https://github.com/maxmind/MaxMind-DB/blob/main/source-data/GeoLite2-City-Test.json
|
||||||
|
self.assertEqual(
|
||||||
|
self.reader.city_dict("2.125.160.216"),
|
||||||
|
{
|
||||||
|
"city": "Boxford",
|
||||||
|
"continent": "EU",
|
||||||
|
"country": "GB",
|
||||||
|
"lat": 51.75,
|
||||||
|
"long": -1.25,
|
||||||
|
},
|
||||||
|
)
|
@ -2,6 +2,7 @@
|
|||||||
from rest_framework.serializers import ModelSerializer
|
from rest_framework.serializers import ModelSerializer
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
|
from authentik.core.api.used_by import UsedByMixin
|
||||||
from authentik.flows.api.stages import StageSerializer
|
from authentik.flows.api.stages import StageSerializer
|
||||||
from authentik.flows.models import FlowStageBinding
|
from authentik.flows.models import FlowStageBinding
|
||||||
|
|
||||||
@ -24,10 +25,11 @@ class FlowStageBindingSerializer(ModelSerializer):
|
|||||||
"re_evaluate_policies",
|
"re_evaluate_policies",
|
||||||
"order",
|
"order",
|
||||||
"policy_engine_mode",
|
"policy_engine_mode",
|
||||||
|
"invalid_response_action",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class FlowStageBindingViewSet(ModelViewSet):
|
class FlowStageBindingViewSet(UsedByMixin, ModelViewSet):
|
||||||
"""FlowStageBinding Viewset"""
|
"""FlowStageBinding Viewset"""
|
||||||
|
|
||||||
queryset = FlowStageBinding.objects.all()
|
queryset = FlowStageBinding.objects.all()
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user