Compare commits
1428 Commits
version-20
...
version/20
Author | SHA1 | Date | |
---|---|---|---|
2788329880 | |||
15ab11be70 | |||
8d5460a132 | |||
5ba2c80813 | |||
06766bdb25 | |||
fdae13316c | |||
ae21886e8e | |||
f5dc81907a | |||
40f8ce3c4c | |||
c934915776 | |||
d70c8fbcc3 | |||
12b26e49ec | |||
0ac548d56e | |||
e771e1857f | |||
479e9750c7 | |||
c5e7801247 | |||
48ea15a946 | |||
e4c06f7356 | |||
4d7d866e4b | |||
72a93c0959 | |||
73733b20b6 | |||
3872314931 | |||
85c6ede448 | |||
49c2bee9d6 | |||
6b2c9d7c44 | |||
381010600f | |||
2a265f706a | |||
1b21b50b77 | |||
fa6324ab1d | |||
9e0daf2bcf | |||
0273ae16df | |||
f2f12ef0ba | |||
61d3df5f02 | |||
971de4fcb9 | |||
9c0bc78ca0 | |||
92085f1a3c | |||
6067406e96 | |||
9ccd4d69fe | |||
17ec48332d | |||
d3f5253a6b | |||
7a70726d57 | |||
be303937fb | |||
2326fc9ae2 | |||
9374b0bcf2 | |||
47e6028099 | |||
24114e8304 | |||
921d9c79a1 | |||
1119989ab7 | |||
e17594f0f7 | |||
5ae3b868d4 | |||
37ee4af5ff | |||
829aaca317 | |||
8eb4d53810 | |||
e60dfc5b3c | |||
cc403d8777 | |||
b81e2e69d1 | |||
731f5d0199 | |||
a40cb03b44 | |||
f6a85c98c9 | |||
5727f28784 | |||
6fc54ed7c6 | |||
4298900ecc | |||
f04aa09b72 | |||
3647633232 | |||
2e06786869 | |||
eba91c6b2b | |||
ba9f8a5795 | |||
02b4173d30 | |||
61fab497cf | |||
6a95de4e8a | |||
621e7f564a | |||
535f2eb27e | |||
0db4716e92 | |||
c10ce5c679 | |||
070438aabe | |||
71798b931c | |||
8663134c87 | |||
6bcbaeec2e | |||
17ce113c6b | |||
ff600cd5b1 | |||
2df4322ecf | |||
bb8e0c6f59 | |||
ca682c3ee4 | |||
f011e8a61a | |||
bfe27d5979 | |||
b8aff17d98 | |||
3b7e8e3931 | |||
03369e2338 | |||
5da7d9a573 | |||
12110e264d | |||
f5049d3d0f | |||
b616253444 | |||
41efe49d27 | |||
86d0e6ce45 | |||
89bb27b95c | |||
9333ffd04f | |||
2b155964c2 | |||
c3bd509eb8 | |||
72c0da2bdf | |||
151c62733f | |||
dbdea24290 | |||
909c4217bc | |||
922fc9b8d5 | |||
2c06eed8e7 | |||
a1b3af401d | |||
92d38f62b5 | |||
98a56c77e3 | |||
e5906a4115 | |||
20c6874bb4 | |||
222d3bd358 | |||
02c15f7c43 | |||
ab200eb855 | |||
9e8ce012e3 | |||
00dc8f8b1f | |||
ce812e14c7 | |||
8d32a53126 | |||
f9b6b1dd3f | |||
9679be39fa | |||
0225bf9c99 | |||
8040e2b6e4 | |||
56a56ffdbf | |||
afedcc0074 | |||
4d93e30147 | |||
f62786e58b | |||
f76c1a6f93 | |||
56871523e7 | |||
5f9dda2e58 | |||
0c55eea678 | |||
19a343dadb | |||
3ab9798f38 | |||
dd9dc7e596 | |||
797e31696a | |||
9a42c5815d | |||
f341479732 | |||
8eddb4b95b | |||
5c58532121 | |||
4b7399f454 | |||
27982a771c | |||
8296d0c94c | |||
9bc9568008 | |||
07d619d257 | |||
6ee7d5bf9c | |||
634375c43f | |||
10fc33f7d3 | |||
ee140014e9 | |||
2d363948b6 | |||
dcb3ef14d1 | |||
a71ef7f36c | |||
4d51ec906d | |||
cd42281383 | |||
faf706cbec | |||
16c05a7bbc | |||
2ad5995332 | |||
f73a404fd6 | |||
178e8e7e43 | |||
98907ec889 | |||
9dd9ab6da3 | |||
80c6b8f0c7 | |||
8436814874 | |||
3c16bdce45 | |||
a2bce79796 | |||
3e5b05203b | |||
57e86582d1 | |||
dd7cb45733 | |||
2b09d97522 | |||
d39dbc7287 | |||
48f96ea55f | |||
22a7c25526 | |||
cc69311ec0 | |||
15d7004e25 | |||
ddb70a283e | |||
ecfc3a6d93 | |||
5753182e03 | |||
db79244ba4 | |||
3231bcea66 | |||
5e0299ca82 | |||
42e35aace0 | |||
d96cfc8e30 | |||
36c97afc44 | |||
9c322be8d7 | |||
cf09205933 | |||
e851a7f294 | |||
e4f141c6c0 | |||
35fa93d9aa | |||
2bdc0102f9 | |||
aef9d27706 | |||
7bf587af24 | |||
ef1cf7867c | |||
da443b443c | |||
f4322e665a | |||
e22b8f5fdc | |||
a18176af56 | |||
4132fd139c | |||
b077bb8783 | |||
69665d9547 | |||
d0f056357d | |||
9ed236f7ab | |||
83f4830946 | |||
e23df99a9e | |||
b80ecd4668 | |||
66ca488ea0 | |||
d959b7a930 | |||
62ae3f1e31 | |||
619203c177 | |||
a1adf382af | |||
834bddd0da | |||
7d9251ce2f | |||
fb13a46252 | |||
dfefdbfd7c | |||
846c971674 | |||
5b7e1f97e0 | |||
dff0613b3d | |||
0a4343d61b | |||
09696207a6 | |||
8965451073 | |||
994c1c4b6a | |||
3ee5a672f1 | |||
b33ea9cc61 | |||
50a623d8ab | |||
cdbf7ae567 | |||
1307a39042 | |||
dca34cfbd3 | |||
735f7cbd69 | |||
728356d420 | |||
a9f6f1563d | |||
155c28d7cd | |||
f9a180eb1f | |||
4ae476e58d | |||
f32d35b07c | |||
9e936e4436 | |||
649abddea7 | |||
956382b682 | |||
67b88595ad | |||
b4ee693a5c | |||
57e5acaf2f | |||
050ec99c89 | |||
10fd1c8120 | |||
070745e764 | |||
cbeee27fc1 | |||
2bc4d0cedb | |||
5105a1c207 | |||
64e357ab0e | |||
6ca93525aa | |||
a2c978768c | |||
f0c7be7144 | |||
0f96e3e4b3 | |||
d42fc37a88 | |||
4ecd8f5dcf | |||
d7a194b512 | |||
753f8d38bf | |||
118a54517a | |||
8c27616d0c | |||
e444d0d640 | |||
3869965b4c | |||
097a42bb7b | |||
26f1f47cc1 | |||
471f9c6d05 | |||
d4e1b95991 | |||
67d13f19a1 | |||
1b7c19cf50 | |||
b012ae600d | |||
1838101d60 | |||
929add4e9c | |||
18edaea658 | |||
8030e45d75 | |||
d75c63d38b | |||
52889ffea1 | |||
2b730dec54 | |||
2aacb311bc | |||
40055ef01b | |||
6c603cdf80 | |||
5f4a1417b2 | |||
75608dce5c | |||
b0f7083879 | |||
e8420957b1 | |||
62bf79ce32 | |||
7a16c9cb14 | |||
d29d161ac6 | |||
aee58c8d53 | |||
c47ab4f1fc | |||
fa6df84de2 | |||
1faa403fe2 | |||
653631ac77 | |||
cde303e780 | |||
7f5feb9451 | |||
b85aeae5ef | |||
aa359a032c | |||
6491065aab | |||
79eec5a3a0 | |||
cd5e091937 | |||
7ed8952803 | |||
c1f302fb7c | |||
cb31e52d0e | |||
782764ac73 | |||
d0c56325ef | |||
73d57d6f82 | |||
2716a26887 | |||
0452537e8b | |||
d1a1bfbbc5 | |||
a69fcbca9a | |||
1ac4dacc3b | |||
b72b731320 | |||
65de4b8cad | |||
9e7e22367b | |||
9301b27e43 | |||
7b415a24ee | |||
f5761dc70d | |||
4f57dfda93 | |||
16380b3f7a | |||
b0e416e9f0 | |||
16f2603130 | |||
e742494f3d | |||
5fdca722f4 | |||
847cfed73f | |||
19247accd9 | |||
05b587ae44 | |||
a515afae0b | |||
8da00585e3 | |||
b70a72f247 | |||
11160b6e04 | |||
55259adf38 | |||
3f308ad48c | |||
ee6fd6f609 | |||
d53d0c353f | |||
1360b76d1b | |||
e22a286a6f | |||
62c0f69541 | |||
1c340ddbbd | |||
bcf7e162a4 | |||
62af5b2dd3 | |||
f44956bd61 | |||
e0859686c4 | |||
cb37e5c10e | |||
73bb778d62 | |||
b612a82e16 | |||
83991c743e | |||
09f43ca43b | |||
1c91835a26 | |||
c032914092 | |||
3634bf4629 | |||
0692663537 | |||
b5649bdcc4 | |||
418e491799 | |||
fab9a10487 | |||
9778050dda | |||
9ac808ee98 | |||
0f00b27384 | |||
ab5981836d | |||
a4418a83f8 | |||
36b23c4624 | |||
0c6237d8c4 | |||
e546453250 | |||
5b35d71bb3 | |||
cddff85e1c | |||
c65c6a62cc | |||
1bc51adcac | |||
c523b799be | |||
9d0d779f40 | |||
8a791c4eac | |||
036a4e86e2 | |||
4715e7bf04 | |||
45f99fbaf0 | |||
83150d9920 | |||
e31a3307b5 | |||
d28fcca344 | |||
c296e1214c | |||
d30dcda814 | |||
c720c9f41b | |||
62cfb76b39 | |||
d676cf6e3f | |||
39d87841d0 | |||
fcd879034c | |||
b285814e24 | |||
1c52836060 | |||
f3cc1be0f2 | |||
8dd77793a0 | |||
f6e8dbfb5e | |||
3c1ac4c7ec | |||
52bbf454e3 | |||
1252c6b07d | |||
3493d35af9 | |||
f8e4ffbc85 | |||
faca127217 | |||
f88575cec4 | |||
1a6ea72c09 | |||
b4eac771c2 | |||
84e4ec4406 | |||
c251b87f8c | |||
21a9aa229a | |||
5f6565ee27 | |||
afad55a357 | |||
f25d76fa43 | |||
53e15bfbca | |||
8bce16e6b4 | |||
e9bb8c896b | |||
de5455716d | |||
1d879400f2 | |||
5136ae17f5 | |||
10b45d954e | |||
339eaf37f2 | |||
f723fdd551 | |||
4cb8ae760a | |||
e4898f4b92 | |||
a2f3c54c2a | |||
c0a0b52fbb | |||
8359f0bfb3 | |||
ee610a906a | |||
828eeb5ebb | |||
c9c177d8f9 | |||
c19afa4f16 | |||
cfd4817bb5 | |||
94ae52b576 | |||
be479f2453 | |||
c5d066577d | |||
9ec6eaf4b8 | |||
b057120351 | |||
b8082598a1 | |||
1b5a163f46 | |||
1f2f48a7bc | |||
f9ad102915 | |||
ea4b920264 | |||
7d8390ca77 | |||
7ae551da65 | |||
51b26c2ac7 | |||
e4a5f22f9b | |||
2462d58135 | |||
44534153a0 | |||
facfea035b | |||
941bc61b31 | |||
282b364606 | |||
ad4bc4083d | |||
ebe282eb1a | |||
830c26ca25 | |||
ed3b4a3d4a | |||
975c4ddc04 | |||
7e2896298a | |||
cba9cf8361 | |||
bf12580f64 | |||
75ef4ce596 | |||
c2f3ce11b0 | |||
3c256fecc6 | |||
0285b84133 | |||
99a371a02c | |||
c7e6eb8896 | |||
674bd9e05c | |||
b79901df87 | |||
b248f450dd | |||
05db9e5c40 | |||
234a5e2b66 | |||
aea1736f70 | |||
9f4a4449f5 | |||
b6b55e2336 | |||
8f2805e05b | |||
4f3583cd7e | |||
617e90dca3 | |||
f7408626a8 | |||
4dcb15af46 | |||
89beb7a9f7 | |||
28eeb4798e | |||
79b92e764e | |||
919336a519 | |||
27e04589c1 | |||
ba44fbdac8 | |||
0e093a8917 | |||
d0bfb99859 | |||
93bdea3769 | |||
e681654af7 | |||
cab7593dca | |||
cf92f9aefc | |||
8d72b3498d | |||
42ab858c50 | |||
a1abae9ab1 | |||
8f36b49061 | |||
64b4e851ce | |||
40a62ac1e5 | |||
5df60e4d87 | |||
50ebc8522d | |||
eddca478dc | |||
99a7fca08e | |||
a7e3602908 | |||
74169860cf | |||
52bb774f73 | |||
f26fcaf825 | |||
b8e92e2f11 | |||
08adfc94d6 | |||
236fafb735 | |||
5ad9ddee3c | |||
24d220ff49 | |||
3364c195b7 | |||
50aa87d141 | |||
72b375023d | |||
77ba186818 | |||
2fe6de0505 | |||
bf9e969b53 | |||
184f119b16 | |||
ebc06f1abe | |||
0f8880ab0a | |||
ee56da5092 | |||
2152004502 | |||
45d0b80d02 | |||
96065eb942 | |||
ac944fee8b | |||
1d0e5fc353 | |||
1f97420207 | |||
ae07f13a87 | |||
0aec504170 | |||
3b4c9bcc57 | |||
5182a6741e | |||
da7635ae5c | |||
a92a0fb60a | |||
cb10c1753b | |||
ae654bd4c8 | |||
28192655ec | |||
9582294eb8 | |||
0172430d7d | |||
1454b65933 | |||
432a7792e2 | |||
54069618b4 | |||
81feb313df | |||
e6b275add3 | |||
27016a5527 | |||
4c29d517f0 | |||
180d27cc37 | |||
5a8b356dc7 | |||
3195640776 | |||
f463296d47 | |||
adf4b23c01 | |||
d900a2b6a9 | |||
95a2fddfa8 | |||
8f7d21b692 | |||
3f84abec2f | |||
b5c857aff4 | |||
f8dee09107 | |||
84a800583c | |||
88de94f014 | |||
25549ec339 | |||
fe4923bff6 | |||
bb1a0b6bd2 | |||
879b5ead71 | |||
1670ec9167 | |||
ac52667327 | |||
0d7c5c2108 | |||
73e3d19384 | |||
f6e0f0282d | |||
3f42067a8f | |||
ed6f5b98df | |||
dd290e264c | |||
c85484fc00 | |||
663dffd8be | |||
c15d0c3d17 | |||
bf09a54f35 | |||
930dd51663 | |||
12a523c7aa | |||
ea9a6d57dd | |||
91958e1232 | |||
8925afb089 | |||
ccafe7be4f | |||
8279690a8f | |||
763d3ae76a | |||
b775e7f4d3 | |||
3d8d93ece5 | |||
06af306e8a | |||
9257f3c919 | |||
2fe7f4cf04 | |||
04399bc8bb | |||
fcbcfbc3c0 | |||
3e4ce62dfe | |||
d8292151e6 | |||
3d01a59b34 | |||
5df15c4105 | |||
75d695105d | |||
28189bdddf | |||
f6885c7cf8 | |||
2c43f0824e | |||
13e2eea72f | |||
9441be1ee2 | |||
d7ab2a362a | |||
e920be3a72 | |||
f771383c4b | |||
65c75f085a | |||
17503365f7 | |||
ebf9f0ca63 | |||
ae26d2756f | |||
124071f9be | |||
471f7d9c62 | |||
a6a6b3bd06 | |||
48ad3dccda | |||
341c58a722 | |||
9b04f2da48 | |||
f7a296544f | |||
78641a57ad | |||
a77ff5ffec | |||
bdd5e16db1 | |||
d4672bfe79 | |||
abd9fab41a | |||
7c8bf42ef9 | |||
274b555912 | |||
916530f0d8 | |||
95efd47f65 | |||
90ecb1af7f | |||
d7fdca1b44 | |||
37346763dc | |||
c35fd2755f | |||
281e3a0518 | |||
6349cdad2f | |||
ef341dd405 | |||
198e5ce642 | |||
923fbac5b0 | |||
5f28c7ace7 | |||
d96c96006f | |||
3ddf2d6f85 | |||
ba6849f29c | |||
942170f902 | |||
248f993541 | |||
56d40bddd0 | |||
3a700a449a | |||
a20f552bcf | |||
32331a56eb | |||
d752b7e41c | |||
0b4223c6ca | |||
a3ec5c13f0 | |||
128b582dd6 | |||
e59ede5422 | |||
6d08ba2513 | |||
23444f4df0 | |||
3338f7a401 | |||
b126519275 | |||
71e68b498e | |||
fb267ee223 | |||
8e59b06611 | |||
a4b3519428 | |||
4895fc3bbb | |||
3daabd6fa8 | |||
9fccb14065 | |||
12efe94fd1 | |||
375ef27b9f | |||
9a7fa39de4 | |||
c779ad2e3b | |||
7e7ef289ba | |||
223d9ad414 | |||
948ea7b087 | |||
bf771f8b6c | |||
6dc8aa396c | |||
92a48f9dc6 | |||
d0ad9fcb1f | |||
539e6deca5 | |||
df4c8003b8 | |||
169e748a78 | |||
39b365c6ae | |||
9a79bab43d | |||
e229eda96e | |||
4448145aa9 | |||
3d042e708a | |||
2428d5f1c2 | |||
f1dc2b4d2a | |||
7dfbcdbb81 | |||
5fd4f56fa2 | |||
b9d5ba6b0a | |||
2a4cb07ba8 | |||
7939286176 | |||
46ef49b897 | |||
b923d85f6a | |||
2862b4ecfb | |||
094acc62f0 | |||
13d17dc729 | |||
5cf3a13ca8 | |||
d0898a3869 | |||
7158c9d2ea | |||
c5cf17b60b | |||
da58796768 | |||
d98499a3fa | |||
e5944567e8 | |||
d296c12d01 | |||
4c3a9e69f2 | |||
eb2540a3c8 | |||
bf9a3615d9 | |||
33fb22e3e7 | |||
f3ff398a44 | |||
533eb59a04 | |||
8ca29f6d49 | |||
0a33d38adf | |||
f7afb60c1f | |||
b9c605bf1a | |||
2983adc719 | |||
502393ee56 | |||
121bba1d9f | |||
3c1b70c355 | |||
27508dd1f0 | |||
6d962dbdf3 | |||
9194e6368a | |||
917fb7d626 | |||
3cf5794b96 | |||
631b0a1819 | |||
6662dcc4b0 | |||
95db54b819 | |||
bc7d5042df | |||
de3e1c3dbc | |||
3c6aac5435 | |||
eeb755ab7d | |||
70d0dd51a5 | |||
073dd8b560 | |||
b5d2924d46 | |||
597e279f34 | |||
fc28def83d | |||
f6efdfded4 | |||
91312496e0 | |||
b557b4337d | |||
bfde186aa0 | |||
2bd75dd1a9 | |||
27ab31a9b0 | |||
44a8b737d9 | |||
b939ee7a09 | |||
0bae550520 | |||
b5cc2f2bda | |||
9ad4cf1db9 | |||
9dbafaaea2 | |||
2db8b07578 | |||
7c1a7bfd9d | |||
b7ef076798 | |||
37c29a073e | |||
0c288ea64b | |||
2476475174 | |||
71913c8164 | |||
6ec8432217 | |||
7a12c0e4d1 | |||
23a7eba16b | |||
3ba84a8e8b | |||
75476217a0 | |||
7771c0b905 | |||
3378e82ec7 | |||
126e43dea4 | |||
f725009530 | |||
70d1e3a0cb | |||
e751ce1220 | |||
e09a27cf87 | |||
06fbf44724 | |||
200e409d91 | |||
5e5854e256 | |||
3df8bcfc9c | |||
e76c14f9e0 | |||
6b6748b1c7 | |||
d92d8e6dbb | |||
c2b9dc5c75 | |||
5c1d27de2b | |||
6ab9e7cd68 | |||
3ef56e9ec1 | |||
6d8d157772 | |||
cadd466eec | |||
3fea0c1e49 | |||
4c58201adc | |||
4fb4e72624 | |||
276d8fe5cf | |||
92ce5f0931 | |||
7fea20375f | |||
d4d4034d2c | |||
f0db408699 | |||
5e200655d9 | |||
d5d1f2a645 | |||
cc5cc43baa | |||
e512f085db | |||
f323c01bd8 | |||
f56cacb406 | |||
eaecd31e9f | |||
36989d82e1 | |||
50777d9022 | |||
a15571bd3e | |||
26fd66d831 | |||
0be873025a | |||
28ada49910 | |||
4fc8e61f8c | |||
7d26ea1a9c | |||
3a58dc62e1 | |||
71fe7bc827 | |||
933336c38b | |||
371feb9a31 | |||
95a2fd3c9e | |||
17cb76c334 | |||
88f0dfc8cc | |||
f82aada23b | |||
ecaee92634 | |||
89252ec47b | |||
f0f25ab291 | |||
e4d0fec15a | |||
6b10baf086 | |||
f148b5d341 | |||
1471ff8940 | |||
d9a6ec2ac0 | |||
5745ffa0a8 | |||
b26202db35 | |||
6318577a51 | |||
6a2cd45847 | |||
ef5cea2c01 | |||
69f4d54bae | |||
b1eec5a7d2 | |||
1b8271d767 | |||
3e9f5ec5ef | |||
63f57b6a77 | |||
a016f99450 | |||
adc18b2991 | |||
e37a326b95 | |||
048467e97d | |||
cc2cd6919f | |||
0c6e781e5b | |||
7294d8fca5 | |||
16ec5680b4 | |||
87920fb1d7 | |||
523b96a6d2 | |||
45731d8069 | |||
e872371970 | |||
08e8cf850a | |||
b1ed2154ac | |||
7ef2aa3eb9 | |||
160139813d | |||
582ad92c76 | |||
f61736e3d1 | |||
eb02c96281 | |||
8619552920 | |||
6237352e25 | |||
2d8b4f543b | |||
8542dc10ab | |||
c55b63337c | |||
12ddee3bb6 | |||
dc41d0af27 | |||
3323b50036 | |||
8acb15a7fd | |||
f601e04b38 | |||
f50529cb5b | |||
3f1b6f9ed4 | |||
f1ab0f4314 | |||
4d1129f385 | |||
03ac9c6e16 | |||
c0839924f1 | |||
91e3aa760a | |||
5c0681d57b | |||
c4f72c2bc1 | |||
e92f9836e3 | |||
3818dc834b | |||
cda011a049 | |||
897f6f3473 | |||
b70b44490b | |||
77a5a58cb9 | |||
f3b227434e | |||
2ae164df78 | |||
9b09793230 | |||
f8a401aeca | |||
ffbab2cd68 | |||
734e5fcab4 | |||
78578c6c9d | |||
0ccec96490 | |||
8022d0801d | |||
d79975c409 | |||
20d65035d5 | |||
8d6227377f | |||
4bc50e7f57 | |||
945e42c940 | |||
052bb28086 | |||
4a84b7e2d5 | |||
4d27694706 | |||
16cfa8cae2 | |||
1a20c8ffc1 | |||
d7ad5f6a16 | |||
5af9a3d3be | |||
dec34bc948 | |||
cff37caa57 | |||
cc6d5765f2 | |||
2ec1ff2ebb | |||
884c2bd0e9 | |||
2c938ec9dc | |||
9733caf3b7 | |||
494af0a430 | |||
10e50bc77f | |||
44bfbb9e49 | |||
5be152e12d | |||
b0efab6d6d | |||
f2725b88c8 | |||
24cc123029 | |||
d75c9997f6 | |||
0a20a30af3 | |||
c60ba91fee | |||
37927c9361 | |||
0a63441935 | |||
6b7a8b6ac7 | |||
cba255eaaa | |||
859cf2bd8f | |||
a2578ffaad | |||
888526a2a7 | |||
0d00b9cc0d | |||
27cc5d7138 | |||
b2f077645a | |||
2878597603 | |||
5face5410f | |||
1b8750e13b | |||
e27a6fdeeb | |||
a9af40f85c | |||
59f04963be | |||
033c9a3bd3 | |||
09e3d616e9 | |||
0b280c0a47 | |||
07a4f474f4 | |||
244dc671db | |||
4308136108 | |||
69a0153619 | |||
2655768f5a | |||
73c55b56a0 | |||
bcbdd6c26f | |||
00e9b91f56 | |||
4cf76fdcda | |||
c4832206fa | |||
d05562a388 | |||
f217d34a98 | |||
89f2967f69 | |||
9a6a3e66b8 | |||
2f4b18ebbd | |||
20572c728d | |||
aad753de68 | |||
a79a150a1f | |||
8b23e4701a | |||
a366d61891 | |||
9a13dfd63a | |||
32d80829e2 | |||
f6953296d8 | |||
e4790f9060 | |||
58712047e1 | |||
85915905dc | |||
52f2838f57 | |||
12e2f7b945 | |||
45d47f828a | |||
cf7eb88661 | |||
6a14ae7975 | |||
08f3294a1d | |||
ac47fc9295 | |||
1ff19e1467 | |||
439454a71b | |||
2a11964e1a | |||
507b8d43fb | |||
7efec281be | |||
9469f86f65 | |||
e998919097 | |||
450d69a1a4 | |||
b74681f22c | |||
f95a7c26e5 | |||
ffc9bd2cec | |||
bb7db0c828 | |||
aec3e08201 | |||
0651fbba06 | |||
7639cdad0a | |||
6533f48912 | |||
2024dac39a | |||
33d5cd2973 | |||
b003e8e1e8 | |||
294d70ae4d | |||
23fd257624 | |||
3e909ae6bb | |||
ff24bc8cb8 | |||
ecf35cfd1d | |||
673520c9f8 | |||
b4f738492d | |||
00a666856d | |||
bff7addb55 | |||
2a90c0b35e | |||
93e27d1959 | |||
02c736d784 | |||
2015d91484 | |||
6433b5982e | |||
f0bc90738f | |||
970a4baf49 | |||
5fbefef56f | |||
1110038eb0 | |||
e945c250db | |||
b46d08cc97 | |||
18eccd995d | |||
6f06ba06d0 | |||
495b068be5 | |||
84c4547005 | |||
065121d280 | |||
8c943e187b | |||
ee54a8b33d | |||
373d94635f | |||
31422c6836 | |||
bca59a2b5a | |||
4ff3bc59b7 | |||
bd9cd086a0 | |||
a6b1ee949d | |||
f93e2c5eb6 | |||
8fe38b528b | |||
38dbde191c | |||
39434053b9 | |||
5bdc1a3ddc | |||
14fb0c3d61 | |||
c52afe5952 | |||
36e6d5e394 | |||
1d4b941a3b | |||
0344e5d9b3 | |||
d8e8cc062b | |||
0a6efab7cb | |||
c8dc299ae3 | |||
700c66f312 | |||
04861b1b00 | |||
06badf88b2 | |||
67ab4305ad | |||
b35e62e5ae | |||
051016f613 | |||
295f0fe730 | |||
54b7ef42f5 | |||
669b5db8e5 | |||
4882de6ade | |||
95ceabe1ba | |||
769a3424dc | |||
47070261b0 | |||
0d5a7f9b44 | |||
07ceaa20f3 | |||
d1403f6f7d | |||
9430a2eea2 | |||
2592fc3826 | |||
d9ece98bbc | |||
1524efcf51 | |||
8cceacb33f | |||
3b13f322de | |||
a570189c73 | |||
c92c0102ca | |||
c6dddc97f0 | |||
38292a588b | |||
01e54cb986 | |||
e90da9283e | |||
e0e0f4fa6c | |||
90426802fd | |||
8b28039c1b | |||
cdf57d7eea | |||
b237f2ddfb | |||
784a3efaa5 | |||
9e0c4e7e08 | |||
7e62b82d56 | |||
c079f9e339 | |||
72d42249e2 | |||
f9e826d553 | |||
0f5e0a774a | |||
34fe250fb0 | |||
92990b4ded | |||
9e2f165dd8 | |||
88891c99bc | |||
93de363c86 | |||
7db3be604c | |||
ec95a2bddc | |||
de9d483b9f | |||
0c9c3153b5 | |||
557724768a | |||
68608087ec | |||
3118365118 | |||
1f821521c6 | |||
281a460960 | |||
0e131e6b2f | |||
ca9e632b57 | |||
184aa25513 | |||
80df444067 | |||
d18e829d80 | |||
c5dfe189f7 | |||
29f6f1d54f | |||
e952bd671f | |||
421c7df536 | |||
f322198020 | |||
c392aa607d | |||
4e368d1e8d | |||
229468175a | |||
e1f7421c6a | |||
7a836e0d7e | |||
5b57d67b5f | |||
4cd3466e56 | |||
f496b8b5d7 | |||
3d5eebda3b | |||
a26e5f3b17 | |||
fe91bff854 | |||
03958d170b | |||
837fa23af0 | |||
665c1aa81b | |||
ebc6afe015 | |||
45bee4b4dc | |||
c025d64ba3 | |||
a9ef1a3190 | |||
2a53bc4330 | |||
8180d6f9e8 | |||
ccfc1dbcc2 | |||
16f0f89a9d | |||
c5976de500 | |||
1781ab59ba | |||
3367b83368 | |||
f21bb319d0 | |||
f0a8c30ce9 | |||
571049219f | |||
260f0b8710 | |||
787f5a1e96 | |||
b36a3100e6 | |||
e02207f38d | |||
3eafa4711e | |||
9a8240bdd1 | |||
f6ab241219 | |||
ff579fd387 | |||
1693118df7 | |||
b0f09eb2c4 | |||
9c9addb0ce | |||
decb91e5f1 | |||
b39339409a | |||
0d75ce45c3 | |||
8801e39e65 | |||
0faa91c1fe | |||
2d5094fdf7 | |||
8044818a4d | |||
9703e32c1b | |||
f28bfdaeb9 | |||
fdd8e66b91 | |||
562eb8af95 | |||
a43fb026a0 | |||
29b88d0e5c | |||
18211a2033 | |||
48c980e8e7 | |||
b4cfc56e5e | |||
667ccbe00e | |||
6af2c6a014 | |||
8e797fa76b | |||
1b91543add | |||
1cd59be8dc | |||
6fe5175f21 | |||
90775d5122 | |||
e52390aa28 | |||
fea493f3a0 | |||
5803575ee2 | |||
1a17ce24f9 | |||
ddd5047cc3 | |||
919946609d | |||
d861a0cec9 | |||
6ea83edd9f | |||
66bb68a747 | |||
13a8ad3126 | |||
e83465517b | |||
bc23197643 | |||
f887c257f8 | |||
1d4017d94a | |||
8f9e8bb9dd | |||
ded9060af2 | |||
579697b978 | |||
200391c533 | |||
5384a06cb5 | |||
aa4f7fb2b6 | |||
4f1c11c5ef | |||
04486d65dc | |||
a449f9c69b | |||
36b346662c | |||
9d392931df | |||
2c60ec50be | |||
77ed25ae34 | |||
b87903a209 | |||
87a418de25 | |||
683d10fa70 | |||
8e84d74634 | |||
d783c632ad | |||
756f3dbedc | |||
eff2e3aeb0 | |||
fb3e302f44 | |||
24d2c94e7c | |||
400adaa282 | |||
6d67ad8451 | |||
7ad1656369 | |||
79b1b21931 | |||
9c9bcb7a01 | |||
add7a80fdc | |||
aac91c2e9d | |||
85e86351cd | |||
75fec19079 | |||
a939e224fc | |||
1fc2bcf02b | |||
b7bfb93928 | |||
d767504474 | |||
f84cd6208c | |||
1ec540ea9a | |||
4e5dba1d0b | |||
92a448b677 | |||
f875149983 | |||
29fe731bbf | |||
d70b81fe43 | |||
a64dbc94c1 | |||
26e66969c9 | |||
fe629f8b51 | |||
b58c913618 | |||
9665e33156 | |||
96d7a5a27f | |||
05aefefb61 | |||
f5dc8c045e | |||
72b7642c5a | |||
a97f842112 | |||
16e6e4c3b7 | |||
dc0d715885 | |||
7ecd57ecff | |||
1e1f17aceb | |||
35c1476bbe | |||
18bb4fd0bf | |||
ac77291b6d | |||
5571aa32b6 | |||
66c3535bcb | |||
293c479364 | |||
f9382b8458 | |||
c9fe28dad7 | |||
8bb57a1283 | |||
55a5300bd2 | |||
0cb4d64b57 | |||
a4fd58a0db | |||
8ceef82c55 | |||
f933cd99ad | |||
e5b63377a0 | |||
6c81a1929d | |||
e5269306df | |||
fb6e8ca1eb | |||
7ac5091e5a | |||
bc9ff792a8 | |||
4c41948e75 | |||
a5c8caf909 | |||
970655ab21 | |||
8495ff9fc0 | |||
309cd90c43 | |||
acbc0ee5cc | |||
a60f6e426f | |||
6fd86aa357 | |||
f1e32b989d | |||
6aebbec270 | |||
b86fd7b716 | |||
5693a794b4 | |||
c8c7202c61 | |||
a3981dd3cd | |||
affafc31cf | |||
602aed674b | |||
f01bc20d44 | |||
1b03aae7aa | |||
7eb97cd2bc | |||
8aaec3b149 | |||
4c9b49e7a6 | |||
903d1ecc6e | |||
f2197d63f1 | |||
9c0f7e0018 | |||
75ff2480e2 | |||
bc7f84fff4 | |||
1b638adf89 | |||
7eebc40e00 | |||
33ddccf066 | |||
efc8452e72 | |||
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 | |||
3dc9e247d5 | |||
2a0bd50e23 | |||
ff42663d3c | |||
ce49d7ea5b | |||
8429dd19b2 | |||
1554dc9feb | |||
1005f341e4 | |||
b98895ac2c | |||
6dc38b0132 | |||
e154e28611 | |||
690b7be1d8 |
@ -1,5 +1,5 @@
|
|||||||
[bumpversion]
|
[bumpversion]
|
||||||
current_version = 2021.6.4
|
current_version = 2021.10.1
|
||||||
tag = True
|
tag = True
|
||||||
commit = True
|
commit = True
|
||||||
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\-?(?P<release>.*)
|
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\-?(?P<release>.*)
|
||||||
@ -23,14 +23,12 @@ values =
|
|||||||
|
|
||||||
[bumpversion:file:schema.yml]
|
[bumpversion:file:schema.yml]
|
||||||
|
|
||||||
[bumpversion:file:.github/workflows/release.yml]
|
[bumpversion:file:.github/workflows/release-publish.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:website/docs/outposts/manual-deploy-docker-compose.md]
|
[bumpversion:file:website/docs/outposts/manual-deploy-docker-compose.md]
|
||||||
|
@ -3,3 +3,6 @@ static
|
|||||||
htmlcov
|
htmlcov
|
||||||
*.env.yml
|
*.env.yml
|
||||||
**/node_modules
|
**/node_modules
|
||||||
|
dist/**
|
||||||
|
build/**
|
||||||
|
build_docs/**
|
||||||
|
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -27,7 +27,7 @@ If applicable, add screenshots to help explain your problem.
|
|||||||
Output of docker-compose logs or kubectl logs respectively
|
Output of docker-compose logs or kubectl logs respectively
|
||||||
|
|
||||||
**Version and Deployment (please complete the following information):**
|
**Version and Deployment (please complete the following information):**
|
||||||
- authentik version: [e.g. 0.10.0-stable]
|
- authentik version: [e.g. 2021.8.5]
|
||||||
- Deployment: [e.g. docker-compose, helm]
|
- Deployment: [e.g. docker-compose, helm]
|
||||||
|
|
||||||
**Additional context**
|
**Additional context**
|
||||||
|
2
.github/ISSUE_TEMPLATE/question.md
vendored
2
.github/ISSUE_TEMPLATE/question.md
vendored
@ -20,7 +20,7 @@ If applicable, add screenshots to help explain your problem.
|
|||||||
Output of docker-compose logs or kubectl logs respectively
|
Output of docker-compose logs or kubectl logs respectively
|
||||||
|
|
||||||
**Version and Deployment (please complete the following information):**
|
**Version and Deployment (please complete the following information):**
|
||||||
- authentik version: [e.g. 0.10.0-stable]
|
- authentik version: [e.g. 2021.8.5]
|
||||||
- Deployment: [e.g. docker-compose, helm]
|
- Deployment: [e.g. docker-compose, helm]
|
||||||
|
|
||||||
**Additional context**
|
**Additional context**
|
||||||
|
3
.github/codespell-words.txt
vendored
Normal file
3
.github/codespell-words.txt
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
keypair
|
||||||
|
keypairs
|
||||||
|
hass
|
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.
|
316
.github/workflows/ci-main.yml
vendored
Normal file
316
.github/workflows/ci-main.yml
vendored
Normal file
@ -0,0 +1,316 @@
|
|||||||
|
name: authentik-ci-main
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- next
|
||||||
|
- version-*
|
||||||
|
paths-ignore:
|
||||||
|
- website
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
env:
|
||||||
|
POSTGRES_DB: authentik
|
||||||
|
POSTGRES_USER: authentik
|
||||||
|
POSTGRES_PASSWORD: "EK-5jnKfjrGRm<77"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint-pylint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.9'
|
||||||
|
- id: cache-pipenv
|
||||||
|
uses: actions/cache@v2.1.6
|
||||||
|
with:
|
||||||
|
path: ~/.local/share/virtualenvs
|
||||||
|
key: ${{ runner.os }}-pipenv-v2-${{ hashFiles('**/Pipfile.lock') }}
|
||||||
|
- name: prepare
|
||||||
|
env:
|
||||||
|
INSTALL: ${{ steps.cache-pipenv.outputs.cache-hit }}
|
||||||
|
run: scripts/ci_prepare.sh
|
||||||
|
- name: run pylint
|
||||||
|
run: pipenv run pylint authentik tests lifecycle
|
||||||
|
lint-black:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.9'
|
||||||
|
- id: cache-pipenv
|
||||||
|
uses: actions/cache@v2.1.6
|
||||||
|
with:
|
||||||
|
path: ~/.local/share/virtualenvs
|
||||||
|
key: ${{ runner.os }}-pipenv-v2-${{ hashFiles('**/Pipfile.lock') }}
|
||||||
|
- name: prepare
|
||||||
|
env:
|
||||||
|
INSTALL: ${{ steps.cache-pipenv.outputs.cache-hit }}
|
||||||
|
run: scripts/ci_prepare.sh
|
||||||
|
- name: run black
|
||||||
|
run: pipenv run black --check authentik tests lifecycle
|
||||||
|
lint-isort:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.9'
|
||||||
|
- id: cache-pipenv
|
||||||
|
uses: actions/cache@v2.1.6
|
||||||
|
with:
|
||||||
|
path: ~/.local/share/virtualenvs
|
||||||
|
key: ${{ runner.os }}-pipenv-v2-${{ hashFiles('**/Pipfile.lock') }}
|
||||||
|
- name: prepare
|
||||||
|
env:
|
||||||
|
INSTALL: ${{ steps.cache-pipenv.outputs.cache-hit }}
|
||||||
|
run: scripts/ci_prepare.sh
|
||||||
|
- name: run isort
|
||||||
|
run: pipenv run isort --check authentik tests lifecycle
|
||||||
|
lint-bandit:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.9'
|
||||||
|
- id: cache-pipenv
|
||||||
|
uses: actions/cache@v2.1.6
|
||||||
|
with:
|
||||||
|
path: ~/.local/share/virtualenvs
|
||||||
|
key: ${{ runner.os }}-pipenv-v2-${{ hashFiles('**/Pipfile.lock') }}
|
||||||
|
- name: prepare
|
||||||
|
env:
|
||||||
|
INSTALL: ${{ steps.cache-pipenv.outputs.cache-hit }}
|
||||||
|
run: scripts/ci_prepare.sh
|
||||||
|
- name: run bandit
|
||||||
|
run: pipenv run bandit -r authentik tests lifecycle
|
||||||
|
lint-pyright:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.9'
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: '16'
|
||||||
|
- name: prepare
|
||||||
|
run: |
|
||||||
|
scripts/ci_prepare.sh
|
||||||
|
npm install -g pyright@1.1.136
|
||||||
|
- name: run bandit
|
||||||
|
run: pipenv run pyright e2e lifecycle
|
||||||
|
test-migrations:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.9'
|
||||||
|
- id: cache-pipenv
|
||||||
|
uses: actions/cache@v2.1.6
|
||||||
|
with:
|
||||||
|
path: ~/.local/share/virtualenvs
|
||||||
|
key: ${{ runner.os }}-pipenv-v2-${{ hashFiles('**/Pipfile.lock') }}
|
||||||
|
- name: prepare
|
||||||
|
env:
|
||||||
|
INSTALL: ${{ steps.cache-pipenv.outputs.cache-hit }}
|
||||||
|
run: scripts/ci_prepare.sh
|
||||||
|
- name: run migrations
|
||||||
|
run: pipenv run python -m lifecycle.migrate
|
||||||
|
test-migrations-from-stable:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.9'
|
||||||
|
- name: prepare variables
|
||||||
|
id: ev
|
||||||
|
run: |
|
||||||
|
python ./scripts/gh_env.py
|
||||||
|
- id: cache-pipenv
|
||||||
|
uses: actions/cache@v2.1.6
|
||||||
|
with:
|
||||||
|
path: ~/.local/share/virtualenvs
|
||||||
|
key: ${{ runner.os }}-pipenv-v2-${{ hashFiles('**/Pipfile.lock') }}
|
||||||
|
- name: checkout stable
|
||||||
|
run: |
|
||||||
|
# Copy current, latest config to local
|
||||||
|
cp authentik/lib/default.yml local.env.yml
|
||||||
|
git checkout $(git describe --abbrev=0 --match 'version/*')
|
||||||
|
- name: prepare
|
||||||
|
env:
|
||||||
|
INSTALL: ${{ steps.cache-pipenv.outputs.cache-hit }}
|
||||||
|
run: |
|
||||||
|
scripts/ci_prepare.sh
|
||||||
|
# Sync anyways since stable will have different dependencies
|
||||||
|
pipenv sync --dev
|
||||||
|
- name: run migrations to stable
|
||||||
|
run: pipenv run python -m lifecycle.migrate
|
||||||
|
- name: checkout current code
|
||||||
|
run: |
|
||||||
|
set -x
|
||||||
|
git fetch
|
||||||
|
git checkout ${{ steps.ev.outputs.branchName }}
|
||||||
|
pipenv sync --dev
|
||||||
|
- name: prepare
|
||||||
|
env:
|
||||||
|
INSTALL: ${{ steps.cache-pipenv.outputs.cache-hit }}
|
||||||
|
run: scripts/ci_prepare.sh
|
||||||
|
- name: migrate to latest
|
||||||
|
run: pipenv run python -m lifecycle.migrate
|
||||||
|
test-unittest:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.9'
|
||||||
|
- id: cache-pipenv
|
||||||
|
uses: actions/cache@v2.1.6
|
||||||
|
with:
|
||||||
|
path: ~/.local/share/virtualenvs
|
||||||
|
key: ${{ runner.os }}-pipenv-v2-${{ hashFiles('**/Pipfile.lock') }}
|
||||||
|
- name: prepare
|
||||||
|
env:
|
||||||
|
INSTALL: ${{ steps.cache-pipenv.outputs.cache-hit }}
|
||||||
|
run: scripts/ci_prepare.sh
|
||||||
|
- uses: testspace-com/setup-testspace@v1
|
||||||
|
with:
|
||||||
|
domain: ${{github.repository_owner}}
|
||||||
|
- name: run unittest
|
||||||
|
run: |
|
||||||
|
pipenv run make test
|
||||||
|
pipenv run coverage xml
|
||||||
|
- name: run testspace
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: |
|
||||||
|
testspace [unittest]unittest.xml --link=codecov
|
||||||
|
- if: ${{ always() }}
|
||||||
|
uses: codecov/codecov-action@v2
|
||||||
|
test-integration:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.9'
|
||||||
|
- id: cache-pipenv
|
||||||
|
uses: actions/cache@v2.1.6
|
||||||
|
with:
|
||||||
|
path: ~/.local/share/virtualenvs
|
||||||
|
key: ${{ runner.os }}-pipenv-v2-${{ hashFiles('**/Pipfile.lock') }}
|
||||||
|
- name: prepare
|
||||||
|
env:
|
||||||
|
INSTALL: ${{ steps.cache-pipenv.outputs.cache-hit }}
|
||||||
|
run: scripts/ci_prepare.sh
|
||||||
|
- uses: testspace-com/setup-testspace@v1
|
||||||
|
with:
|
||||||
|
domain: ${{github.repository_owner}}
|
||||||
|
- name: Create k8s Kind Cluster
|
||||||
|
uses: helm/kind-action@v1.2.0
|
||||||
|
- name: run integration
|
||||||
|
run: |
|
||||||
|
pipenv run make test-integration
|
||||||
|
pipenv run coverage xml
|
||||||
|
- name: run testspace
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: |
|
||||||
|
testspace [integration]unittest.xml --link=codecov
|
||||||
|
- if: ${{ always() }}
|
||||||
|
uses: codecov/codecov-action@v2
|
||||||
|
test-e2e:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.9'
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: '16'
|
||||||
|
cache: 'npm'
|
||||||
|
cache-dependency-path: web/package-lock.json
|
||||||
|
- uses: testspace-com/setup-testspace@v1
|
||||||
|
with:
|
||||||
|
domain: ${{github.repository_owner}}
|
||||||
|
- id: cache-pipenv
|
||||||
|
uses: actions/cache@v2.1.6
|
||||||
|
with:
|
||||||
|
path: ~/.local/share/virtualenvs
|
||||||
|
key: ${{ runner.os }}-pipenv-v2-${{ hashFiles('**/Pipfile.lock') }}
|
||||||
|
- name: prepare
|
||||||
|
env:
|
||||||
|
INSTALL: ${{ steps.cache-pipenv.outputs.cache-hit }}
|
||||||
|
run: |
|
||||||
|
scripts/ci_prepare.sh
|
||||||
|
docker-compose -f tests/e2e/docker-compose.yml up -d
|
||||||
|
- id: cache-web
|
||||||
|
uses: actions/cache@v2.1.6
|
||||||
|
with:
|
||||||
|
path: web/dist
|
||||||
|
key: ${{ runner.os }}-web-${{ hashFiles('web/package-lock.json', 'web/**') }}
|
||||||
|
- name: prepare web ui
|
||||||
|
if: steps.cache-web.outputs.cache-hit != 'true'
|
||||||
|
run: |
|
||||||
|
cd web
|
||||||
|
npm i
|
||||||
|
npm run build
|
||||||
|
- name: run e2e
|
||||||
|
run: |
|
||||||
|
pipenv run make test-e2e
|
||||||
|
pipenv run coverage xml
|
||||||
|
- name: run testspace
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: |
|
||||||
|
testspace [e2e]unittest.xml --link=codecov
|
||||||
|
- if: ${{ always() }}
|
||||||
|
uses: codecov/codecov-action@v2
|
||||||
|
build:
|
||||||
|
needs:
|
||||||
|
- lint-pylint
|
||||||
|
- lint-black
|
||||||
|
- lint-isort
|
||||||
|
- lint-bandit
|
||||||
|
- lint-pyright
|
||||||
|
- test-migrations
|
||||||
|
- test-migrations-from-stable
|
||||||
|
- test-unittest
|
||||||
|
- test-integration
|
||||||
|
- test-e2e
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
- name: prepare variables
|
||||||
|
id: ev
|
||||||
|
env:
|
||||||
|
DOCKER_USERNAME: ${{ secrets.HARBOR_USERNAME }}
|
||||||
|
run: |
|
||||||
|
python ./scripts/gh_env.py
|
||||||
|
- name: Login to Container Registry
|
||||||
|
uses: docker/login-action@v1
|
||||||
|
if: ${{ steps.ev.outputs.shouldBuild == 'true' }}
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.repository_owner }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Building Docker Image
|
||||||
|
uses: docker/build-push-action@v2
|
||||||
|
with:
|
||||||
|
push: ${{ steps.ev.outputs.shouldBuild == 'true' }}
|
||||||
|
tags: |
|
||||||
|
ghcr.io/goauthentik/dev-server:gh-${{ steps.ev.outputs.branchNameContainer }}
|
||||||
|
ghcr.io/goauthentik/dev-server:gh-${{ steps.ev.outputs.branchNameContainer }}-${{ steps.ev.outputs.timestamp }}-${{ steps.ev.outputs.sha }}
|
||||||
|
build-args: |
|
||||||
|
GIT_BUILD_HASH=${{ steps.ev.outputs.sha }}
|
69
.github/workflows/ci-outpost.yml
vendored
Normal file
69
.github/workflows/ci-outpost.yml
vendored
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
name: authentik-ci-outpost
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- next
|
||||||
|
- version-*
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint-golint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: '^1.16.3'
|
||||||
|
- name: Run linter
|
||||||
|
run: |
|
||||||
|
# Create folder structure for go embeds
|
||||||
|
mkdir -p web/dist
|
||||||
|
mkdir -p website/help
|
||||||
|
touch web/dist/test website/help/test
|
||||||
|
docker run \
|
||||||
|
--rm \
|
||||||
|
-v $(pwd):/app \
|
||||||
|
-w /app \
|
||||||
|
golangci/golangci-lint:v1.39.0 \
|
||||||
|
golangci-lint run -v --timeout 200s
|
||||||
|
build:
|
||||||
|
needs:
|
||||||
|
- lint-golint
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
type:
|
||||||
|
- proxy
|
||||||
|
- ldap
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
- name: prepare variables
|
||||||
|
id: ev
|
||||||
|
env:
|
||||||
|
DOCKER_USERNAME: ${{ secrets.HARBOR_USERNAME }}
|
||||||
|
run: |
|
||||||
|
python ./scripts/gh_env.py
|
||||||
|
- name: Login to Container Registry
|
||||||
|
uses: docker/login-action@v1
|
||||||
|
if: ${{ steps.ev.outputs.shouldBuild == 'true' }}
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.repository_owner }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Building Docker Image
|
||||||
|
uses: docker/build-push-action@v2
|
||||||
|
with:
|
||||||
|
push: ${{ steps.ev.outputs.shouldBuild == 'true' }}
|
||||||
|
tags: |
|
||||||
|
ghcr.io/goauthentik/dev-${{ matrix.type }}:gh-${{ steps.ev.outputs.branchNameContainer }}
|
||||||
|
ghcr.io/goauthentik/dev-${{ matrix.type }}:gh-${{ steps.ev.outputs.branchNameContainer }}-${{ steps.ev.outputs.timestamp }}
|
||||||
|
ghcr.io/goauthentik/dev-${{ matrix.type }}:gh-${{ steps.ev.outputs.sha }}
|
||||||
|
file: ${{ matrix.type }}.Dockerfile
|
||||||
|
build-args: |
|
||||||
|
GIT_BUILD_HASH=${{ steps.ev.outputs.sha }}
|
89
.github/workflows/ci-web.yml
vendored
Normal file
89
.github/workflows/ci-web.yml
vendored
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
name: authentik-ci-web
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- next
|
||||||
|
- version-*
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint-eslint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: '16'
|
||||||
|
cache: 'npm'
|
||||||
|
cache-dependency-path: web/package-lock.json
|
||||||
|
- run: |
|
||||||
|
cd web
|
||||||
|
npm install
|
||||||
|
- name: Generate API
|
||||||
|
run: make gen-web
|
||||||
|
- name: Eslint
|
||||||
|
run: |
|
||||||
|
cd web
|
||||||
|
npm run lint
|
||||||
|
lint-prettier:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: '16'
|
||||||
|
cache: 'npm'
|
||||||
|
cache-dependency-path: web/package-lock.json
|
||||||
|
- run: |
|
||||||
|
cd web
|
||||||
|
npm install
|
||||||
|
- name: Generate API
|
||||||
|
run: make gen-web
|
||||||
|
- name: prettier
|
||||||
|
run: |
|
||||||
|
cd web
|
||||||
|
npm run prettier-check
|
||||||
|
lint-lit-analyse:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: '16'
|
||||||
|
cache: 'npm'
|
||||||
|
cache-dependency-path: web/package-lock.json
|
||||||
|
- run: |
|
||||||
|
cd web
|
||||||
|
npm install
|
||||||
|
- name: Generate API
|
||||||
|
run: make gen-web
|
||||||
|
- name: lit-analyse
|
||||||
|
run: |
|
||||||
|
cd web
|
||||||
|
npm run lit-analyse
|
||||||
|
build:
|
||||||
|
needs:
|
||||||
|
- lint-eslint
|
||||||
|
- lint-prettier
|
||||||
|
- lint-lit-analyse
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: '16'
|
||||||
|
cache: 'npm'
|
||||||
|
cache-dependency-path: web/package-lock.json
|
||||||
|
- run: |
|
||||||
|
cd web
|
||||||
|
npm install
|
||||||
|
- name: Generate API
|
||||||
|
run: make gen-web
|
||||||
|
- name: build
|
||||||
|
run: |
|
||||||
|
cd web
|
||||||
|
npm run build
|
60
.github/workflows/codeql-analysis.yml
vendored
Normal file
60
.github/workflows/codeql-analysis.yml
vendored
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
name: "CodeQL"
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master, '*', next, version* ]
|
||||||
|
pull_request:
|
||||||
|
# The branches below must be a subset of the branches above
|
||||||
|
branches: [ master ]
|
||||||
|
schedule:
|
||||||
|
- cron: '30 6 * * 5'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analyze:
|
||||||
|
name: Analyze
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
actions: read
|
||||||
|
contents: read
|
||||||
|
security-events: write
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
language: [ 'go', 'javascript', 'python' ]
|
||||||
|
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||||
|
# Learn more:
|
||||||
|
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
# Initializes the CodeQL tools for scanning.
|
||||||
|
- name: Initialize CodeQL
|
||||||
|
uses: github/codeql-action/init@v1
|
||||||
|
with:
|
||||||
|
languages: ${{ matrix.language }}
|
||||||
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
|
# By default, queries listed here will override any specified in a config file.
|
||||||
|
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||||
|
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||||
|
|
||||||
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
|
- name: Autobuild
|
||||||
|
uses: github/codeql-action/autobuild@v1
|
||||||
|
|
||||||
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
|
# 📚 https://git.io/JvXDl
|
||||||
|
|
||||||
|
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||||
|
# and modify them (or add more) to build your code if your project
|
||||||
|
# uses a compiled language
|
||||||
|
|
||||||
|
#- run: |
|
||||||
|
# make bootstrap
|
||||||
|
# make release
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v1
|
22
.github/workflows/ghcr-retention.yml
vendored
Normal file
22
.github/workflows/ghcr-retention.yml
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
name: ghcr-retention
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 0 * * *' # every day at midnight
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
clean-ghcr:
|
||||||
|
name: Delete old unused container images
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Delete 'dev' containers older than a week
|
||||||
|
uses: sondrelg/container-retention-policy@v1
|
||||||
|
with:
|
||||||
|
image-names: dev-server,dev-ldap,dev-proxy
|
||||||
|
cut-off: One week ago UTC
|
||||||
|
account-type: org
|
||||||
|
org-name: goauthentik
|
||||||
|
untagged-only: false
|
||||||
|
token: ${{ secrets.GHCR_CLEANUP_TOKEN }}
|
||||||
|
skip-tags: gh-next,gh-master
|
@ -3,9 +3,6 @@ name: authentik-on-release
|
|||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
types: [published, created]
|
types: [published, created]
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- version-*
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# Build
|
# Build
|
||||||
@ -33,14 +30,14 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
push: ${{ github.event_name == 'release' }}
|
push: ${{ github.event_name == 'release' }}
|
||||||
tags: |
|
tags: |
|
||||||
beryju/authentik:2021.6.4,
|
beryju/authentik:2021.10.1,
|
||||||
beryju/authentik:latest,
|
beryju/authentik:latest,
|
||||||
ghcr.io/goauthentik/server:2021.6.4,
|
ghcr.io/goauthentik/server:2021.10.1,
|
||||||
ghcr.io/goauthentik/server:latest
|
ghcr.io/goauthentik/server:latest
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
context: .
|
context: .
|
||||||
- name: Building Docker Image (stable)
|
- name: Building Docker Image (stable)
|
||||||
if: ${{ github.event_name == 'release' && !contains('2021.6.4', 'rc') }}
|
if: ${{ github.event_name == 'release' && !contains('2021.10.1', 'rc') }}
|
||||||
run: |
|
run: |
|
||||||
docker pull beryju/authentik:latest
|
docker pull beryju/authentik:latest
|
||||||
docker tag beryju/authentik:latest beryju/authentik:stable
|
docker tag beryju/authentik:latest beryju/authentik:stable
|
||||||
@ -75,14 +72,14 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
push: ${{ github.event_name == 'release' }}
|
push: ${{ github.event_name == 'release' }}
|
||||||
tags: |
|
tags: |
|
||||||
beryju/authentik-proxy:2021.6.4,
|
beryju/authentik-proxy:2021.10.1,
|
||||||
beryju/authentik-proxy:latest,
|
beryju/authentik-proxy:latest,
|
||||||
ghcr.io/goauthentik/proxy:2021.6.4,
|
ghcr.io/goauthentik/proxy:2021.10.1,
|
||||||
ghcr.io/goauthentik/proxy:latest
|
ghcr.io/goauthentik/proxy:latest
|
||||||
file: outpost/proxy.Dockerfile
|
file: proxy.Dockerfile
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
- name: Building Docker Image (stable)
|
- name: Building Docker Image (stable)
|
||||||
if: ${{ github.event_name == 'release' && !contains('2021.6.4', 'rc') }}
|
if: ${{ github.event_name == 'release' && !contains('2021.10.1', 'rc') }}
|
||||||
run: |
|
run: |
|
||||||
docker pull beryju/authentik-proxy:latest
|
docker pull beryju/authentik-proxy:latest
|
||||||
docker tag beryju/authentik-proxy:latest beryju/authentik-proxy:stable
|
docker tag beryju/authentik-proxy:latest beryju/authentik-proxy:stable
|
||||||
@ -117,14 +114,14 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
push: ${{ github.event_name == 'release' }}
|
push: ${{ github.event_name == 'release' }}
|
||||||
tags: |
|
tags: |
|
||||||
beryju/authentik-ldap:2021.6.4,
|
beryju/authentik-ldap:2021.10.1,
|
||||||
beryju/authentik-ldap:latest,
|
beryju/authentik-ldap:latest,
|
||||||
ghcr.io/goauthentik/ldap:2021.6.4,
|
ghcr.io/goauthentik/ldap:2021.10.1,
|
||||||
ghcr.io/goauthentik/ldap:latest
|
ghcr.io/goauthentik/ldap:latest
|
||||||
file: outpost/ldap.Dockerfile
|
file: ldap.Dockerfile
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
- name: Building Docker Image (stable)
|
- name: Building Docker Image (stable)
|
||||||
if: ${{ github.event_name == 'release' && !contains('2021.6.4', 'rc') }}
|
if: ${{ github.event_name == 'release' && !contains('2021.10.1', 'rc') }}
|
||||||
run: |
|
run: |
|
||||||
docker pull beryju/authentik-ldap:latest
|
docker pull beryju/authentik-ldap:latest
|
||||||
docker tag beryju/authentik-ldap:latest beryju/authentik-ldap:stable
|
docker tag beryju/authentik-ldap:latest beryju/authentik-ldap:stable
|
||||||
@ -142,28 +139,25 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Run test suite in final docker images
|
- name: Run test suite in final docker images
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get install -y pwgen
|
echo "PG_PASS=$(openssl rand -base64 32)" >> .env
|
||||||
echo "PG_PASS=$(pwgen 40 1)" >> .env
|
echo "AUTHENTIK_SECRET_KEY=$(openssl rand -base64 32)" >> .env
|
||||||
echo "AUTHENTIK_SECRET_KEY=$(pwgen 50 1)" >> .env
|
|
||||||
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 server test
|
docker-compose run -u root server test
|
||||||
sentry-release:
|
sentry-release:
|
||||||
if: ${{ github.event_name == 'release' }}
|
|
||||||
needs:
|
needs:
|
||||||
- test-release
|
- test-release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Setup Node.js environment
|
- name: Setup Node.js environment
|
||||||
uses: actions/setup-node@v2.2.0
|
uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: 12.x
|
node-version: '16'
|
||||||
- name: Build web api client and web ui
|
- name: Build web api client and web ui
|
||||||
run: |
|
run: |
|
||||||
export NODE_ENV=production
|
export NODE_ENV=production
|
||||||
make gen-web
|
|
||||||
cd web
|
cd web
|
||||||
npm i
|
npm i
|
||||||
npm run build
|
npm run build
|
||||||
@ -176,7 +170,7 @@ jobs:
|
|||||||
SENTRY_PROJECT: authentik
|
SENTRY_PROJECT: authentik
|
||||||
SENTRY_URL: https://sentry.beryju.org
|
SENTRY_URL: https://sentry.beryju.org
|
||||||
with:
|
with:
|
||||||
version: authentik@2021.6.4
|
version: authentik@2021.10.1
|
||||||
environment: beryjuorg-prod
|
environment: beryjuorg-prod
|
||||||
sourcemaps: './web/dist'
|
sourcemaps: './web/dist'
|
||||||
finalize: false
|
url_prefix: '~/static/dist'
|
@ -13,21 +13,20 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Pre-release test
|
- name: Pre-release test
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get install -y pwgen
|
echo "PG_PASS=$(openssl rand -base64 32)" >> .env
|
||||||
echo "AUTHENTIK_TAG=latest" >> .env
|
echo "AUTHENTIK_SECRET_KEY=$(openssl rand -base64 32)" >> .env
|
||||||
echo "PG_PASS=$(pwgen 40 1)" >> .env
|
|
||||||
echo "AUTHENTIK_SECRET_KEY=$(pwgen 50 1)" >> .env
|
|
||||||
docker-compose pull -q
|
|
||||||
docker build \
|
docker build \
|
||||||
--no-cache \
|
--no-cache \
|
||||||
-t ghcr.io/goauthentik/server:latest \
|
-t testing:latest \
|
||||||
-f Dockerfile .
|
-f Dockerfile .
|
||||||
|
echo "AUTHENTIK_IMAGE=testing" >> .env
|
||||||
|
echo "AUTHENTIK_TAG=latest" >> .env
|
||||||
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 server test
|
docker-compose run -u root server test
|
||||||
- name: Extract version number
|
- name: Extract version number
|
||||||
id: get_version
|
id: get_version
|
||||||
uses: actions/github-script@v4.0.2
|
uses: actions/github-script@v5
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
script: |
|
script: |
|
46
.github/workflows/translation-compile.yml
vendored
Normal file
46
.github/workflows/translation-compile.yml
vendored
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
name: authentik-backend-translate-compile
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
paths:
|
||||||
|
- '/locale/'
|
||||||
|
schedule:
|
||||||
|
- cron: "0 */2 * * *"
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
POSTGRES_DB: authentik
|
||||||
|
POSTGRES_USER: authentik
|
||||||
|
POSTGRES_PASSWORD: "EK-5jnKfjrGRm<77"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
compile:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.9'
|
||||||
|
- id: cache-pipenv
|
||||||
|
uses: actions/cache@v2.1.6
|
||||||
|
with:
|
||||||
|
path: ~/.local/share/virtualenvs
|
||||||
|
key: ${{ runner.os }}-pipenv-v2-${{ hashFiles('**/Pipfile.lock') }}
|
||||||
|
- name: prepare
|
||||||
|
env:
|
||||||
|
INSTALL: ${{ steps.cache-pipenv.outputs.cache-hit }}
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y gettext
|
||||||
|
scripts/ci_prepare.sh
|
||||||
|
- name: run compile
|
||||||
|
run: pipenv run ./manage.py compilemessages
|
||||||
|
- name: Create Pull Request
|
||||||
|
uses: peter-evans/create-pull-request@v3
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
branch: compile-backend-translation
|
||||||
|
commit-message: "core: compile backend translations"
|
||||||
|
title: "core: compile backend translations"
|
||||||
|
delete-branch: true
|
||||||
|
signoff: true
|
39
.github/workflows/web-api-publish.yml
vendored
Normal file
39
.github/workflows/web-api-publish.yml
vendored
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
name: authentik-web-api-publish
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
paths:
|
||||||
|
- 'schema.yml'
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
# Setup .npmrc file to publish to npm
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: '16'
|
||||||
|
registry-url: 'https://registry.npmjs.org'
|
||||||
|
- name: Generate API Client
|
||||||
|
run: make gen-web
|
||||||
|
- name: Publish package
|
||||||
|
run: |
|
||||||
|
cd web-api/
|
||||||
|
npm i
|
||||||
|
npm publish
|
||||||
|
env:
|
||||||
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
|
||||||
|
- name: Upgrade /web
|
||||||
|
run: |
|
||||||
|
cd web/
|
||||||
|
export VERSION=`node -e 'console.log(require("../web-api/package.json").version)'`
|
||||||
|
npm i @goauthentik/api@$VERSION
|
||||||
|
- name: Create Pull Request
|
||||||
|
uses: peter-evans/create-pull-request@v3
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
branch: update-web-api-client
|
||||||
|
commit-message: "web: Update Web API Client version"
|
||||||
|
title: "web: Update Web API Client version"
|
||||||
|
delete-branch: true
|
||||||
|
signoff: true
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -200,3 +200,5 @@ media/
|
|||||||
*mmdb
|
*mmdb
|
||||||
|
|
||||||
.idea/
|
.idea/
|
||||||
|
/api/
|
||||||
|
/web-api/
|
||||||
|
22
.vscode/settings.json
vendored
Normal file
22
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"cSpell.words": [
|
||||||
|
"asgi",
|
||||||
|
"authentik",
|
||||||
|
"authn",
|
||||||
|
"goauthentik",
|
||||||
|
"jwks",
|
||||||
|
"oidc",
|
||||||
|
"openid",
|
||||||
|
"plex",
|
||||||
|
"saml",
|
||||||
|
"totp",
|
||||||
|
"webauthn"
|
||||||
|
],
|
||||||
|
"python.linting.pylintEnabled": true,
|
||||||
|
"todo-tree.tree.showCountsInTree": true,
|
||||||
|
"todo-tree.tree.showBadges": true,
|
||||||
|
"python.formatting.provider": "black",
|
||||||
|
"files.associations": {
|
||||||
|
"*.akflow": "json"
|
||||||
|
}
|
||||||
|
}
|
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.
|
175
CONTRIBUTING.md
Normal file
175
CONTRIBUTING.md
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
# 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)
|
||||||
|
* [The components](#the-components)
|
||||||
|
* [authentik's structure](#authentiks-structure)
|
||||||
|
|
||||||
|
[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)
|
||||||
|
* [Python Styleguide](#python-styleguide)
|
||||||
|
* [Documentation Styleguide](#documentation-styleguide)
|
||||||
|
|
||||||
|
## 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://goauthentik.io/discord)
|
||||||
|
|
||||||
|
## 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 occurred 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/?utm_source=github)
|
||||||
|
|
||||||
|
### 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.
|
41
Dockerfile
41
Dockerfile
@ -1,5 +1,5 @@
|
|||||||
# Stage 1: Lock python dependencies
|
# Stage 1: Lock python dependencies
|
||||||
FROM python:3.9-slim-buster as locker
|
FROM docker.io/python:3.9-slim-buster as locker
|
||||||
|
|
||||||
COPY ./Pipfile /app/
|
COPY ./Pipfile /app/
|
||||||
COPY ./Pipfile.lock /app/
|
COPY ./Pipfile.lock /app/
|
||||||
@ -10,38 +10,36 @@ RUN pip install pipenv && \
|
|||||||
pipenv lock -r > requirements.txt && \
|
pipenv lock -r > requirements.txt && \
|
||||||
pipenv lock -r --dev-only > requirements-dev.txt
|
pipenv lock -r --dev-only > requirements-dev.txt
|
||||||
|
|
||||||
# Stage 2: Build web API
|
# Stage 2: Build website
|
||||||
FROM openapitools/openapi-generator-cli as api-builder
|
FROM docker.io/node:16 as website-builder
|
||||||
|
|
||||||
COPY ./schema.yml /local/schema.yml
|
COPY ./website /static/
|
||||||
|
|
||||||
RUN docker-entrypoint.sh generate \
|
ENV NODE_ENV=production
|
||||||
-i /local/schema.yml \
|
RUN cd /static && npm i && npm run build-docs-only
|
||||||
-g typescript-fetch \
|
|
||||||
-o /local/web/api \
|
|
||||||
--additional-properties=typescriptThreePlus=true,supportsES6=true,npmName=authentik-api,npmVersion=1.0.0
|
|
||||||
|
|
||||||
# Stage 3: Build webui
|
# Stage 3: Build webui
|
||||||
FROM node as npm-builder
|
FROM docker.io/node:16 as web-builder
|
||||||
|
|
||||||
COPY ./web /static/
|
COPY ./web /static/
|
||||||
COPY --from=api-builder /local/web/api /static/api
|
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
RUN cd /static && npm i && npm run build
|
RUN cd /static && npm i && npm run build
|
||||||
|
|
||||||
# Stage 4: Build go proxy
|
# Stage 4: Build go proxy
|
||||||
FROM golang:1.16.5 AS builder
|
FROM docker.io/golang:1.17.2 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/
|
||||||
|
|
||||||
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
|
||||||
@ -49,7 +47,7 @@ COPY ./go.sum /work/go.sum
|
|||||||
RUN go build -o /work/authentik ./cmd/server/main.go
|
RUN go build -o /work/authentik ./cmd/server/main.go
|
||||||
|
|
||||||
# Stage 5: Run
|
# Stage 5: Run
|
||||||
FROM python:3.9-slim-buster
|
FROM docker.io/python:3.9-slim-buster
|
||||||
|
|
||||||
WORKDIR /
|
WORKDIR /
|
||||||
COPY --from=locker /app/requirements.txt /
|
COPY --from=locker /app/requirements.txt /
|
||||||
@ -82,6 +80,11 @@ COPY ./lifecycle/ /lifecycle
|
|||||||
COPY --from=builder /work/authentik /authentik-proxy
|
COPY --from=builder /work/authentik /authentik-proxy
|
||||||
|
|
||||||
USER authentik
|
USER authentik
|
||||||
|
|
||||||
ENV TMPDIR /dev/shm/
|
ENV TMPDIR /dev/shm/
|
||||||
ENV PYTHONUBUFFERED 1
|
ENV PYTHONUNBUFFERED 1
|
||||||
ENTRYPOINT [ "/lifecycle/bootstrap.sh" ]
|
ENV PATH "/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/lifecycle"
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=30s --timeout=30s --start-period=60s --retries=3 CMD [ "/lifecycle/ak", "healthcheck" ]
|
||||||
|
|
||||||
|
ENTRYPOINT [ "/lifecycle/ak" ]
|
||||||
|
38
Makefile
38
Makefile
@ -2,12 +2,11 @@
|
|||||||
PWD = $(shell pwd)
|
PWD = $(shell pwd)
|
||||||
UID = $(shell id -u)
|
UID = $(shell id -u)
|
||||||
GID = $(shell id -g)
|
GID = $(shell id -g)
|
||||||
|
NPM_VERSION = $(shell python -m scripts.npm_version)
|
||||||
|
|
||||||
all: lint-fix lint test gen
|
all: lint-fix lint test gen
|
||||||
|
|
||||||
test-integration:
|
test-integration:
|
||||||
k3d cluster create || exit 0
|
|
||||||
k3d kubeconfig write -o ~/.kube/config --overwrite
|
|
||||||
coverage run manage.py test -v 3 tests/integration
|
coverage run manage.py test -v 3 tests/integration
|
||||||
|
|
||||||
test-e2e:
|
test-e2e:
|
||||||
@ -21,18 +20,30 @@ test:
|
|||||||
lint-fix:
|
lint-fix:
|
||||||
isort authentik tests lifecycle
|
isort authentik tests lifecycle
|
||||||
black authentik tests lifecycle
|
black authentik tests lifecycle
|
||||||
|
codespell -I .github/codespell-words.txt -S 'web/src/locales/**' -w \
|
||||||
|
authentik \
|
||||||
|
internal \
|
||||||
|
cmd \
|
||||||
|
web/src \
|
||||||
|
website/src \
|
||||||
|
website/docs \
|
||||||
|
website/developer-docs
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
pyright authentik tests lifecycle
|
pyright authentik tests lifecycle
|
||||||
bandit -r authentik tests lifecycle -x node_modules
|
bandit -r authentik tests lifecycle -x node_modules
|
||||||
pylint authentik tests lifecycle
|
pylint authentik tests lifecycle
|
||||||
|
|
||||||
|
i18n-extract:
|
||||||
|
./manage.py makemessages --ignore web --ignore internal --ignore web --ignore web-api --ignore website -l en
|
||||||
|
cd web && npm run extract
|
||||||
|
|
||||||
gen-build:
|
gen-build:
|
||||||
./manage.py spectacular --file schema.yml
|
./manage.py spectacular --file schema.yml
|
||||||
|
|
||||||
gen-clean:
|
gen-clean:
|
||||||
rm -rf web/api/src/
|
rm -rf web/api/src/
|
||||||
rm -rf outpost/api/
|
rm -rf api/
|
||||||
|
|
||||||
gen-web:
|
gen-web:
|
||||||
docker run \
|
docker run \
|
||||||
@ -41,9 +52,13 @@ gen-web:
|
|||||||
openapitools/openapi-generator-cli generate \
|
openapitools/openapi-generator-cli generate \
|
||||||
-i /local/schema.yml \
|
-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=@goauthentik/api,npmVersion=${NPM_VERSION}
|
||||||
cd web/api && npx tsc
|
mkdir -p web/node_modules/@goauthentik/api
|
||||||
|
python -m scripts.web_api_esm
|
||||||
|
\cp -fv scripts/web_api_readme.md web-api/README.md
|
||||||
|
cd web-api && npm i
|
||||||
|
\cp -rfv web-api/* web/node_modules/@goauthentik/api
|
||||||
|
|
||||||
gen-outpost:
|
gen-outpost:
|
||||||
docker run \
|
docker run \
|
||||||
@ -55,11 +70,14 @@ gen-outpost:
|
|||||||
--git-user-id api \
|
--git-user-id api \
|
||||||
-i /local/schema.yml \
|
-i /local/schema.yml \
|
||||||
-g go \
|
-g go \
|
||||||
-o /local/outpost/api \
|
-o /local/api \
|
||||||
--additional-properties=packageName=api,enumClassPrefix=true,useOneOfDiscriminatorLookup=true
|
--additional-properties=packageName=api,enumClassPrefix=true,useOneOfDiscriminatorLookup=true,disallowAdditionalPropertiesIfNotPresent=false
|
||||||
rm -f outpost/api/go.mod outpost/api/go.sum
|
rm -f api/go.mod api/go.sum
|
||||||
|
|
||||||
gen: gen-build gen-clean gen-web gen-outpost
|
gen: gen-build gen-clean gen-web
|
||||||
|
|
||||||
|
migrate:
|
||||||
|
python -m lifecycle.migrate
|
||||||
|
|
||||||
run:
|
run:
|
||||||
go run -v cmd/server/main.go
|
go run -v cmd/server/main.go
|
||||||
|
15
Pipfile
15
Pipfile
@ -26,9 +26,9 @@ drf-spectacular = "*"
|
|||||||
facebook-sdk = "*"
|
facebook-sdk = "*"
|
||||||
geoip2 = "*"
|
geoip2 = "*"
|
||||||
gunicorn = "*"
|
gunicorn = "*"
|
||||||
kubernetes = "*"
|
kubernetes = "==v19.15.0"
|
||||||
ldap3 = "*"
|
ldap3 = "*"
|
||||||
lxml = ">=4.6.3"
|
lxml = "*"
|
||||||
packaging = "*"
|
packaging = "*"
|
||||||
psycopg2-binary = "*"
|
psycopg2-binary = "*"
|
||||||
pycryptodome = "*"
|
pycryptodome = "*"
|
||||||
@ -39,7 +39,7 @@ sentry-sdk = "*"
|
|||||||
service_identity = "*"
|
service_identity = "*"
|
||||||
structlog = "*"
|
structlog = "*"
|
||||||
swagger-spec-validator = "*"
|
swagger-spec-validator = "*"
|
||||||
twisted = "==20.3.0"
|
twisted = "==21.7.0"
|
||||||
urllib3 = {extras = ["secure"],version = "*"}
|
urllib3 = {extras = ["secure"],version = "*"}
|
||||||
uvicorn = {extras = ["standard"],version = "*"}
|
uvicorn = {extras = ["standard"],version = "*"}
|
||||||
webauthn = "*"
|
webauthn = "*"
|
||||||
@ -47,16 +47,15 @@ xmlsec = "*"
|
|||||||
duo-client = "*"
|
duo-client = "*"
|
||||||
ua-parser = "*"
|
ua-parser = "*"
|
||||||
deepmerge = "*"
|
deepmerge = "*"
|
||||||
|
colorama = "*"
|
||||||
[requires]
|
codespell = "*"
|
||||||
python_version = "3.9"
|
|
||||||
|
|
||||||
[dev-packages]
|
[dev-packages]
|
||||||
bandit = "*"
|
bandit = "*"
|
||||||
black = "==21.5b1"
|
black = "==21.9b0"
|
||||||
bump2version = "*"
|
bump2version = "*"
|
||||||
colorama = "*"
|
colorama = "*"
|
||||||
coverage = "*"
|
coverage = {extras = ["toml"],version = "*"}
|
||||||
pylint = "*"
|
pylint = "*"
|
||||||
pylint-django = "*"
|
pylint-django = "*"
|
||||||
pytest = "*"
|
pytest = "*"
|
||||||
|
1568
Pipfile.lock
generated
1568
Pipfile.lock
generated
File diff suppressed because it is too large
Load Diff
23
README.md
23
README.md
@ -4,14 +4,15 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[](https://discord.gg/jg33eMhnj6)
|
[](https://goauthentik.io/discord)
|
||||||
[](https://dev.azure.com/beryjuorg/authentik/_build?definitionId=6)
|
[](https://github.com/goauthentik/authentik/actions/workflows/ci-main.yml)
|
||||||
[](https://dev.azure.com/beryjuorg/authentik/_build?definitionId=6)
|
[](https://github.com/goauthentik/authentik/actions/workflows/ci-outpost.yml)
|
||||||
[](https://codecov.io/gh/goauthentik/authentik)
|
[](https://github.com/goauthentik/authentik/actions/workflows/ci-web.yml)
|
||||||

|
[](https://codecov.io/gh/goauthentik/authentik)
|
||||||

|
[](https://goauthentik.testspace.com/)
|
||||||

|

|
||||||
[Transifex](https://www.transifex.com/beryjuorg/authentik/)
|

|
||||||
|
[](https://www.transifex.com/beryjuorg/authentik/)
|
||||||
|
|
||||||
## What is authentik?
|
## What is authentik?
|
||||||
|
|
||||||
@ -19,9 +20,9 @@ authentik is an open-source Identity Provider focused on flexibility and versati
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
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/?utm_source=github)
|
||||||
|
|
||||||
For bigger setups, there is a Helm Chart [here])(https://github.com/goauthentik/helm). 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/?utm_source=github)
|
||||||
|
|
||||||
## Screenshots
|
## Screenshots
|
||||||
|
|
||||||
@ -32,7 +33,7 @@ Light | Dark
|
|||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
See [Development Documentation](https://goauthentik.io/developer-docs/)
|
See [Development Documentation](https://goauthentik.io/developer-docs/?utm_source=github)
|
||||||
|
|
||||||
## Security
|
## Security
|
||||||
|
|
||||||
|
@ -2,10 +2,12 @@
|
|||||||
|
|
||||||
## Supported Versions
|
## Supported Versions
|
||||||
|
|
||||||
|
(.x being the latest patch release for each version)
|
||||||
|
|
||||||
| Version | Supported |
|
| Version | Supported |
|
||||||
| ---------- | ------------------ |
|
| ---------- | ------------------ |
|
||||||
| 2021.4.x | :white_check_mark: |
|
| 2021.8.x | :white_check_mark: |
|
||||||
| 2021.5.x | :white_check_mark: |
|
| 2021.9.x | :white_check_mark: |
|
||||||
|
|
||||||
## Reporting a Vulnerability
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
"""authentik"""
|
"""authentik"""
|
||||||
__version__ = "2021.6.4"
|
__version__ = "2021.10.1"
|
||||||
ENV_GIT_HASH_KEY = "GIT_BUILD_HASH"
|
ENV_GIT_HASH_KEY = "GIT_BUILD_HASH"
|
||||||
|
@ -23,9 +23,7 @@ def get_events_per_1h(**filter_kwargs) -> list[dict[str, int]]:
|
|||||||
date_from = now() - timedelta(days=1)
|
date_from = now() - timedelta(days=1)
|
||||||
result = (
|
result = (
|
||||||
Event.objects.filter(created__gte=date_from, **filter_kwargs)
|
Event.objects.filter(created__gte=date_from, **filter_kwargs)
|
||||||
.annotate(
|
.annotate(age=ExpressionWrapper(now() - F("created"), output_field=DurationField()))
|
||||||
age=ExpressionWrapper(now() - F("created"), output_field=DurationField())
|
|
||||||
)
|
|
||||||
.annotate(age_hours=ExtractHour("age"))
|
.annotate(age_hours=ExtractHour("age"))
|
||||||
.values("age_hours")
|
.values("age_hours")
|
||||||
.annotate(count=Count("pk"))
|
.annotate(count=Count("pk"))
|
||||||
@ -37,8 +35,7 @@ def get_events_per_1h(**filter_kwargs) -> list[dict[str, int]]:
|
|||||||
for hour in range(0, -24, -1):
|
for hour in range(0, -24, -1):
|
||||||
results.append(
|
results.append(
|
||||||
{
|
{
|
||||||
"x_cord": time.mktime((_now + timedelta(hours=hour)).timetuple())
|
"x_cord": time.mktime((_now + timedelta(hours=hour)).timetuple()) * 1000,
|
||||||
* 1000,
|
|
||||||
"y_cord": data[hour * -1],
|
"y_cord": data[hour * -1],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -16,6 +16,8 @@ from rest_framework.response import Response
|
|||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
from authentik.core.api.utils import PassiveSerializer
|
from authentik.core.api.utils import PassiveSerializer
|
||||||
|
from authentik.outposts.managed import MANAGED_OUTPOST
|
||||||
|
from authentik.outposts.models import Outpost
|
||||||
|
|
||||||
|
|
||||||
class RuntimeDict(TypedDict):
|
class RuntimeDict(TypedDict):
|
||||||
@ -32,12 +34,18 @@ class RuntimeDict(TypedDict):
|
|||||||
class SystemSerializer(PassiveSerializer):
|
class SystemSerializer(PassiveSerializer):
|
||||||
"""Get system information."""
|
"""Get system information."""
|
||||||
|
|
||||||
|
env = SerializerMethodField()
|
||||||
http_headers = SerializerMethodField()
|
http_headers = SerializerMethodField()
|
||||||
http_host = SerializerMethodField()
|
http_host = SerializerMethodField()
|
||||||
http_is_secure = SerializerMethodField()
|
http_is_secure = SerializerMethodField()
|
||||||
runtime = SerializerMethodField()
|
runtime = SerializerMethodField()
|
||||||
tenant = SerializerMethodField()
|
tenant = SerializerMethodField()
|
||||||
server_time = SerializerMethodField()
|
server_time = SerializerMethodField()
|
||||||
|
embedded_outpost_host = SerializerMethodField()
|
||||||
|
|
||||||
|
def get_env(self, request: Request) -> dict[str, str]:
|
||||||
|
"""Get Environment"""
|
||||||
|
return os.environ.copy()
|
||||||
|
|
||||||
def get_http_headers(self, request: Request) -> dict[str, str]:
|
def get_http_headers(self, request: Request) -> dict[str, str]:
|
||||||
"""Get HTTP Request headers"""
|
"""Get HTTP Request headers"""
|
||||||
@ -61,9 +69,7 @@ class SystemSerializer(PassiveSerializer):
|
|||||||
return {
|
return {
|
||||||
"python_version": python_version,
|
"python_version": python_version,
|
||||||
"gunicorn_version": ".".join(str(x) for x in gunicorn_version),
|
"gunicorn_version": ".".join(str(x) for x in gunicorn_version),
|
||||||
"environment": "kubernetes"
|
"environment": "kubernetes" if SERVICE_HOST_ENV_NAME in os.environ else "compose",
|
||||||
if SERVICE_HOST_ENV_NAME in os.environ
|
|
||||||
else "compose",
|
|
||||||
"architecture": platform.machine(),
|
"architecture": platform.machine(),
|
||||||
"platform": platform.platform(),
|
"platform": platform.platform(),
|
||||||
"uname": " ".join(platform.uname()),
|
"uname": " ".join(platform.uname()),
|
||||||
@ -77,6 +83,13 @@ class SystemSerializer(PassiveSerializer):
|
|||||||
"""Current server time"""
|
"""Current server time"""
|
||||||
return now()
|
return now()
|
||||||
|
|
||||||
|
def get_embedded_outpost_host(self, request: Request) -> str:
|
||||||
|
"""Get the FQDN configured on the embedded outpost"""
|
||||||
|
outposts = Outpost.objects.filter(managed=MANAGED_OUTPOST)
|
||||||
|
if not outposts.exists():
|
||||||
|
return ""
|
||||||
|
return outposts.first().config.authentik_host
|
||||||
|
|
||||||
|
|
||||||
class SystemView(APIView):
|
class SystemView(APIView):
|
||||||
"""Get system information."""
|
"""Get system information."""
|
||||||
|
@ -92,10 +92,7 @@ class TaskViewSet(ViewSet):
|
|||||||
task_func.delay(*task.task_call_args, **task.task_call_kwargs)
|
task_func.delay(*task.task_call_args, **task.task_call_kwargs)
|
||||||
messages.success(
|
messages.success(
|
||||||
self.request,
|
self.request,
|
||||||
_(
|
_("Successfully re-scheduled Task %(name)s!" % {"name": task.task_name}),
|
||||||
"Successfully re-scheduled Task %(name)s!"
|
|
||||||
% {"name": task.task_name}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
return Response(status=204)
|
return Response(status=204)
|
||||||
except ImportError: # pragma: no cover
|
except ImportError: # pragma: no cover
|
||||||
|
@ -41,9 +41,7 @@ class VersionSerializer(PassiveSerializer):
|
|||||||
|
|
||||||
def get_outdated(self, instance) -> bool:
|
def get_outdated(self, instance) -> bool:
|
||||||
"""Check if we're running the latest version"""
|
"""Check if we're running the latest version"""
|
||||||
return parse(self.get_version_current(instance)) < parse(
|
return parse(self.get_version_current(instance)) < parse(self.get_version_latest(instance))
|
||||||
self.get_version_latest(instance)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class VersionView(APIView):
|
class VersionView(APIView):
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
"""authentik administration overview"""
|
"""authentik administration overview"""
|
||||||
|
from django.conf import settings
|
||||||
from drf_spectacular.utils import extend_schema, inline_serializer
|
from drf_spectacular.utils import extend_schema, inline_serializer
|
||||||
from prometheus_client import Gauge
|
from prometheus_client import Gauge
|
||||||
from rest_framework.fields import IntegerField
|
from rest_framework.fields import IntegerField
|
||||||
@ -17,10 +18,11 @@ class WorkerView(APIView):
|
|||||||
|
|
||||||
permission_classes = [IsAdminUser]
|
permission_classes = [IsAdminUser]
|
||||||
|
|
||||||
@extend_schema(
|
@extend_schema(responses=inline_serializer("Workers", fields={"count": IntegerField()}))
|
||||||
responses=inline_serializer("Workers", fields={"count": IntegerField()})
|
|
||||||
)
|
|
||||||
def get(self, request: Request) -> Response:
|
def get(self, request: Request) -> Response:
|
||||||
"""Get currently connected worker count."""
|
"""Get currently connected worker count."""
|
||||||
count = len(CELERY_APP.control.ping(timeout=0.5))
|
count = len(CELERY_APP.control.ping(timeout=0.5))
|
||||||
|
# In debug we run with `CELERY_TASK_ALWAYS_EAGER`, so tasks are ran on the main process
|
||||||
|
if settings.DEBUG:
|
||||||
|
count += 1
|
||||||
return Response({"count": count})
|
return Response({"count": count})
|
||||||
|
@ -8,3 +8,8 @@ class AuthentikAdminConfig(AppConfig):
|
|||||||
name = "authentik.admin"
|
name = "authentik.admin"
|
||||||
label = "authentik_admin"
|
label = "authentik_admin"
|
||||||
verbose_name = "authentik Admin"
|
verbose_name = "authentik Admin"
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
from authentik.admin.tasks import clear_update_notifications
|
||||||
|
|
||||||
|
clear_update_notifications.delay()
|
||||||
|
@ -6,12 +6,19 @@ 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 prometheus_client import Info
|
||||||
from requests import RequestException, get
|
from requests import RequestException
|
||||||
from structlog.stdlib import get_logger
|
from structlog.stdlib import get_logger
|
||||||
|
|
||||||
from authentik import ENV_GIT_HASH_KEY, __version__
|
from authentik import ENV_GIT_HASH_KEY, __version__
|
||||||
from authentik.events.models import Event, EventAction
|
from authentik.events.models import Event, EventAction, Notification
|
||||||
from authentik.events.monitored_tasks import MonitoredTask, TaskResult, TaskResultStatus
|
from authentik.events.monitored_tasks import (
|
||||||
|
MonitoredTask,
|
||||||
|
TaskResult,
|
||||||
|
TaskResultStatus,
|
||||||
|
prefill_task,
|
||||||
|
)
|
||||||
|
from authentik.lib.config import CONFIG
|
||||||
|
from authentik.lib.utils.http import get_http_session
|
||||||
from authentik.root.celery import CELERY_APP
|
from authentik.root.celery import CELERY_APP
|
||||||
|
|
||||||
LOGGER = get_logger()
|
LOGGER = get_logger()
|
||||||
@ -33,22 +40,36 @@ def _set_prom_info():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@CELERY_APP.task()
|
||||||
|
def clear_update_notifications():
|
||||||
|
"""Clear update notifications on startup if the notification was for the version
|
||||||
|
we're running now."""
|
||||||
|
for notification in Notification.objects.filter(event__action=EventAction.UPDATE_AVAILABLE):
|
||||||
|
if "new_version" not in notification.event.context:
|
||||||
|
continue
|
||||||
|
notification_version = notification.event.context["new_version"]
|
||||||
|
if notification_version == __version__:
|
||||||
|
notification.delete()
|
||||||
|
|
||||||
|
|
||||||
@CELERY_APP.task(bind=True, base=MonitoredTask)
|
@CELERY_APP.task(bind=True, base=MonitoredTask)
|
||||||
|
@prefill_task()
|
||||||
def update_latest_version(self: MonitoredTask):
|
def update_latest_version(self: MonitoredTask):
|
||||||
"""Update latest version info"""
|
"""Update latest version info"""
|
||||||
|
if CONFIG.y_bool("disable_update_check"):
|
||||||
|
cache.set(VERSION_CACHE_KEY, "0.0.0", VERSION_CACHE_TIMEOUT)
|
||||||
|
self.set_status(TaskResult(TaskResultStatus.WARNING, messages=["Version check disabled."]))
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
response = get(
|
response = get_http_session().get(
|
||||||
"https://api.github.com/repos/goauthentik/authentik/releases/latest"
|
"https://version.goauthentik.io/version.json",
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
data = response.json()
|
data = response.json()
|
||||||
tag_name = data.get("tag_name")
|
upstream_version = data.get("stable", {}).get("version")
|
||||||
upstream_version = tag_name.split("/")[1]
|
|
||||||
cache.set(VERSION_CACHE_KEY, upstream_version, VERSION_CACHE_TIMEOUT)
|
cache.set(VERSION_CACHE_KEY, upstream_version, VERSION_CACHE_TIMEOUT)
|
||||||
self.set_status(
|
self.set_status(
|
||||||
TaskResult(
|
TaskResult(TaskResultStatus.SUCCESSFUL, ["Successfully updated latest Version"])
|
||||||
TaskResultStatus.SUCCESSFUL, ["Successfully updated latest Version"]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
_set_prom_info()
|
_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,
|
||||||
@ -62,7 +83,7 @@ def update_latest_version(self: MonitoredTask):
|
|||||||
).exists():
|
).exists():
|
||||||
return
|
return
|
||||||
event_dict = {"new_version": upstream_version}
|
event_dict = {"new_version": upstream_version}
|
||||||
if match := re.search(URL_FINDER, data.get("body", "")):
|
if match := re.search(URL_FINDER, data.get("stable", {}).get("changelog", "")):
|
||||||
event_dict["message"] = f"Changelog: {match.group()}"
|
event_dict["message"] = f"Changelog: {match.group()}"
|
||||||
Event.new(EventAction.UPDATE_AVAILABLE, **event_dict).save()
|
Event.new(EventAction.UPDATE_AVAILABLE, **event_dict).save()
|
||||||
except (RequestException, IndexError) as exc:
|
except (RequestException, IndexError) as exc:
|
||||||
|
@ -27,9 +27,7 @@ class TestAdminAPI(TestCase):
|
|||||||
response = self.client.get(reverse("authentik_api:admin_system_tasks-list"))
|
response = self.client.get(reverse("authentik_api:admin_system_tasks-list"))
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
body = loads(response.content)
|
body = loads(response.content)
|
||||||
self.assertTrue(
|
self.assertTrue(any(task["task_name"] == "clean_expired_models" for task in body))
|
||||||
any(task["task_name"] == "clean_expired_models" for task in body)
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_tasks_single(self):
|
def test_tasks_single(self):
|
||||||
"""Test Task API (read single)"""
|
"""Test Task API (read single)"""
|
||||||
@ -45,9 +43,7 @@ class TestAdminAPI(TestCase):
|
|||||||
self.assertEqual(body["status"], TaskResultStatus.SUCCESSFUL.name)
|
self.assertEqual(body["status"], TaskResultStatus.SUCCESSFUL.name)
|
||||||
self.assertEqual(body["task_name"], "clean_expired_models")
|
self.assertEqual(body["task_name"], "clean_expired_models")
|
||||||
response = self.client.get(
|
response = self.client.get(
|
||||||
reverse(
|
reverse("authentik_api:admin_system_tasks-detail", kwargs={"pk": "qwerqwer"})
|
||||||
"authentik_api:admin_system_tasks-detail", kwargs={"pk": "qwerqwer"}
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 404)
|
self.assertEqual(response.status_code, 404)
|
||||||
|
|
||||||
|
@ -1,81 +1,58 @@
|
|||||||
"""test admin tasks"""
|
"""test admin tasks"""
|
||||||
import json
|
|
||||||
from dataclasses import dataclass
|
|
||||||
from unittest.mock import Mock, patch
|
|
||||||
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from requests.exceptions import RequestException
|
from requests_mock import Mocker
|
||||||
|
|
||||||
from authentik.admin.tasks import VERSION_CACHE_KEY, update_latest_version
|
from authentik.admin.tasks import VERSION_CACHE_KEY, update_latest_version
|
||||||
from authentik.events.models import Event, EventAction
|
from authentik.events.models import Event, EventAction
|
||||||
|
|
||||||
|
RESPONSE_VALID = {
|
||||||
@dataclass
|
"$schema": "https://version.goauthentik.io/schema.json",
|
||||||
class MockResponse:
|
"stable": {
|
||||||
"""Mock class to emulate the methods of requests's Response we need"""
|
"version": "99999999.9999999",
|
||||||
|
"changelog": "See https://goauthentik.io/test",
|
||||||
status_code: int
|
"reason": "bugfix",
|
||||||
response: str
|
},
|
||||||
|
}
|
||||||
def json(self) -> dict:
|
|
||||||
"""Get json parsed response"""
|
|
||||||
return json.loads(self.response)
|
|
||||||
|
|
||||||
def raise_for_status(self):
|
|
||||||
"""raise RequestException if status code is 400 or more"""
|
|
||||||
if self.status_code >= 400:
|
|
||||||
raise RequestException
|
|
||||||
|
|
||||||
|
|
||||||
REQUEST_MOCK_VALID = Mock(
|
|
||||||
return_value=MockResponse(
|
|
||||||
200,
|
|
||||||
"""{
|
|
||||||
"tag_name": "version/99999999.9999999",
|
|
||||||
"body": "https://goauthentik.io/test"
|
|
||||||
}""",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
REQUEST_MOCK_INVALID = Mock(return_value=MockResponse(400, "{}"))
|
|
||||||
|
|
||||||
|
|
||||||
class TestAdminTasks(TestCase):
|
class TestAdminTasks(TestCase):
|
||||||
"""test admin tasks"""
|
"""test admin tasks"""
|
||||||
|
|
||||||
@patch("authentik.admin.tasks.get", REQUEST_MOCK_VALID)
|
|
||||||
def test_version_valid_response(self):
|
def test_version_valid_response(self):
|
||||||
"""Test Update checker with valid response"""
|
"""Test Update checker with valid response"""
|
||||||
update_latest_version.delay().get()
|
with Mocker() as mocker:
|
||||||
self.assertEqual(cache.get(VERSION_CACHE_KEY), "99999999.9999999")
|
mocker.get("https://version.goauthentik.io/version.json", json=RESPONSE_VALID)
|
||||||
self.assertTrue(
|
update_latest_version.delay().get()
|
||||||
Event.objects.filter(
|
self.assertEqual(cache.get(VERSION_CACHE_KEY), "99999999.9999999")
|
||||||
action=EventAction.UPDATE_AVAILABLE,
|
self.assertTrue(
|
||||||
context__new_version="99999999.9999999",
|
|
||||||
context__message="Changelog: https://goauthentik.io/test",
|
|
||||||
).exists()
|
|
||||||
)
|
|
||||||
# test that a consecutive check doesn't create a duplicate event
|
|
||||||
update_latest_version.delay().get()
|
|
||||||
self.assertEqual(
|
|
||||||
len(
|
|
||||||
Event.objects.filter(
|
Event.objects.filter(
|
||||||
action=EventAction.UPDATE_AVAILABLE,
|
action=EventAction.UPDATE_AVAILABLE,
|
||||||
context__new_version="99999999.9999999",
|
context__new_version="99999999.9999999",
|
||||||
context__message="Changelog: https://goauthentik.io/test",
|
context__message="Changelog: https://goauthentik.io/test",
|
||||||
)
|
).exists()
|
||||||
),
|
)
|
||||||
1,
|
# test that a consecutive check doesn't create a duplicate event
|
||||||
)
|
update_latest_version.delay().get()
|
||||||
|
self.assertEqual(
|
||||||
|
len(
|
||||||
|
Event.objects.filter(
|
||||||
|
action=EventAction.UPDATE_AVAILABLE,
|
||||||
|
context__new_version="99999999.9999999",
|
||||||
|
context__message="Changelog: https://goauthentik.io/test",
|
||||||
|
)
|
||||||
|
),
|
||||||
|
1,
|
||||||
|
)
|
||||||
|
|
||||||
@patch("authentik.admin.tasks.get", REQUEST_MOCK_INVALID)
|
|
||||||
def test_version_error(self):
|
def test_version_error(self):
|
||||||
"""Test Update checker with invalid response"""
|
"""Test Update checker with invalid response"""
|
||||||
update_latest_version.delay().get()
|
with Mocker() as mocker:
|
||||||
self.assertEqual(cache.get(VERSION_CACHE_KEY), "0.0.0")
|
mocker.get("https://version.goauthentik.io/version.json", status_code=400)
|
||||||
self.assertFalse(
|
update_latest_version.delay().get()
|
||||||
Event.objects.filter(
|
self.assertEqual(cache.get(VERSION_CACHE_KEY), "0.0.0")
|
||||||
action=EventAction.UPDATE_AVAILABLE, context__new_version="0.0.0"
|
self.assertFalse(
|
||||||
).exists()
|
Event.objects.filter(
|
||||||
)
|
action=EventAction.UPDATE_AVAILABLE, context__new_version="0.0.0"
|
||||||
|
).exists()
|
||||||
|
)
|
||||||
|
@ -3,18 +3,21 @@ from base64 import b64decode
|
|||||||
from binascii import Error
|
from binascii import Error
|
||||||
from typing import Any, Optional, Union
|
from typing import Any, Optional, Union
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from rest_framework.authentication import BaseAuthentication, get_authorization_header
|
from rest_framework.authentication import BaseAuthentication, get_authorization_header
|
||||||
from rest_framework.exceptions import AuthenticationFailed
|
from rest_framework.exceptions import AuthenticationFailed
|
||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
from structlog.stdlib import get_logger
|
from structlog.stdlib import get_logger
|
||||||
|
|
||||||
|
from authentik.core.middleware import KEY_AUTH_VIA, LOCAL
|
||||||
from authentik.core.models import Token, TokenIntents, User
|
from authentik.core.models import Token, TokenIntents, User
|
||||||
|
from authentik.outposts.models import Outpost
|
||||||
|
|
||||||
LOGGER = get_logger()
|
LOGGER = get_logger()
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-many-return-statements
|
# pylint: disable=too-many-return-statements
|
||||||
def token_from_header(raw_header: bytes) -> Optional[Token]:
|
def bearer_auth(raw_header: bytes) -> Optional[User]:
|
||||||
"""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 == "" or " " not in auth_credentials:
|
if auth_credentials == "" or " " not in auth_credentials:
|
||||||
@ -31,15 +34,36 @@ def token_from_header(raw_header: bytes) -> Optional[Token]:
|
|||||||
raise AuthenticationFailed("Malformed header")
|
raise AuthenticationFailed("Malformed header")
|
||||||
# Accept credentials with username and without
|
# Accept credentials with username and without
|
||||||
if ":" in auth_credentials:
|
if ":" in auth_credentials:
|
||||||
_, password = auth_credentials.split(":")
|
_, _, password = auth_credentials.partition(":")
|
||||||
else:
|
else:
|
||||||
password = auth_credentials
|
password = auth_credentials
|
||||||
if password == "": # nosec
|
if password == "": # nosec
|
||||||
raise AuthenticationFailed("Malformed header")
|
raise AuthenticationFailed("Malformed header")
|
||||||
tokens = Token.filter_not_expired(key=password, intent=TokenIntents.INTENT_API)
|
tokens = Token.filter_not_expired(key=password, intent=TokenIntents.INTENT_API)
|
||||||
if not tokens.exists():
|
if not tokens.exists():
|
||||||
raise AuthenticationFailed("Token invalid/expired")
|
user = token_secret_key(password)
|
||||||
return tokens.first()
|
if not user:
|
||||||
|
raise AuthenticationFailed("Token invalid/expired")
|
||||||
|
return user
|
||||||
|
if hasattr(LOCAL, "authentik"):
|
||||||
|
LOCAL.authentik[KEY_AUTH_VIA] = "api_token"
|
||||||
|
return tokens.first().user
|
||||||
|
|
||||||
|
|
||||||
|
def token_secret_key(value: str) -> Optional[User]:
|
||||||
|
"""Check if the token is the secret key
|
||||||
|
and return the service account for the managed outpost"""
|
||||||
|
from authentik.outposts.managed import MANAGED_OUTPOST
|
||||||
|
|
||||||
|
if value != settings.SECRET_KEY:
|
||||||
|
return None
|
||||||
|
outposts = Outpost.objects.filter(managed=MANAGED_OUTPOST)
|
||||||
|
if not outposts:
|
||||||
|
return None
|
||||||
|
if hasattr(LOCAL, "authentik"):
|
||||||
|
LOCAL.authentik[KEY_AUTH_VIA] = "secret_key"
|
||||||
|
outpost = outposts.first()
|
||||||
|
return outpost.user
|
||||||
|
|
||||||
|
|
||||||
class TokenAuthentication(BaseAuthentication):
|
class TokenAuthentication(BaseAuthentication):
|
||||||
@ -49,9 +73,9 @@ class TokenAuthentication(BaseAuthentication):
|
|||||||
"""Token-based authentication using HTTP Bearer authentication"""
|
"""Token-based authentication using HTTP Bearer authentication"""
|
||||||
auth = get_authorization_header(request)
|
auth = get_authorization_header(request)
|
||||||
|
|
||||||
token = token_from_header(auth)
|
user = bearer_auth(auth)
|
||||||
# None is only returned when the header isn't set.
|
# None is only returned when the header isn't set.
|
||||||
if not token:
|
if not user:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return (token.user, None) # pragma: no cover
|
return (user, None) # pragma: no cover
|
||||||
|
@ -33,3 +33,12 @@ class OwnerPermissions(BasePermission):
|
|||||||
if owner != request.user:
|
if owner != request.user:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
class OwnerSuperuserPermissions(OwnerPermissions):
|
||||||
|
"""Similar to OwnerPermissions, except always allow access for superusers"""
|
||||||
|
|
||||||
|
def has_object_permission(self, request: Request, view, obj: Model) -> bool:
|
||||||
|
if request.user.is_superuser:
|
||||||
|
return True
|
||||||
|
return super().has_object_permission(request, view, obj)
|
||||||
|
@ -5,11 +5,12 @@ from typing import Callable, Optional
|
|||||||
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 ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
from structlog.stdlib import get_logger
|
||||||
|
|
||||||
|
LOGGER = get_logger()
|
||||||
|
|
||||||
|
|
||||||
def permission_required(
|
def permission_required(perm: Optional[str] = None, other_perms: Optional[list[str]] = None):
|
||||||
perm: Optional[str] = None, other_perms: Optional[list[str]] = None
|
|
||||||
):
|
|
||||||
"""Check permissions for a single custom action"""
|
"""Check permissions for a single custom action"""
|
||||||
|
|
||||||
def wrapper_outter(func: Callable):
|
def wrapper_outter(func: Callable):
|
||||||
@ -20,10 +21,12 @@ def permission_required(
|
|||||||
if perm:
|
if perm:
|
||||||
obj = self.get_object()
|
obj = self.get_object()
|
||||||
if not request.user.has_perm(perm, obj):
|
if not request.user.has_perm(perm, obj):
|
||||||
|
LOGGER.debug("denying access for object", user=request.user, perm=perm, obj=obj)
|
||||||
return self.permission_denied(request)
|
return self.permission_denied(request)
|
||||||
if other_perms:
|
if other_perms:
|
||||||
for other_perm in other_perms:
|
for other_perm in other_perms:
|
||||||
if not request.user.has_perm(other_perm):
|
if not request.user.has_perm(other_perm):
|
||||||
|
LOGGER.debug("denying access for other", user=request.user, perm=perm)
|
||||||
return self.permission_denied(request)
|
return self.permission_denied(request)
|
||||||
return func(self, request, *args, **kwargs)
|
return func(self, request, *args, **kwargs)
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ from drf_spectacular.types import OpenApiTypes
|
|||||||
|
|
||||||
|
|
||||||
def build_standard_type(obj, **kwargs):
|
def build_standard_type(obj, **kwargs):
|
||||||
"""Build a basic type with optional add ons."""
|
"""Build a basic type with optional add owns."""
|
||||||
schema = build_basic_type(obj)
|
schema = build_basic_type(obj)
|
||||||
schema.update(kwargs)
|
schema.update(kwargs)
|
||||||
return schema
|
return schema
|
||||||
@ -31,7 +31,7 @@ VALIDATION_ERROR = build_object_type(
|
|||||||
"non_field_errors": build_array_type(build_standard_type(OpenApiTypes.STR)),
|
"non_field_errors": build_array_type(build_standard_type(OpenApiTypes.STR)),
|
||||||
"code": build_standard_type(OpenApiTypes.STR),
|
"code": build_standard_type(OpenApiTypes.STR),
|
||||||
},
|
},
|
||||||
required=["detail"],
|
required=[],
|
||||||
additionalProperties={},
|
additionalProperties={},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -63,9 +63,7 @@ def postprocess_schema_responses(result, generator, **kwargs): # noqa: W0613
|
|||||||
method["responses"].setdefault("400", validation_error.ref)
|
method["responses"].setdefault("400", validation_error.ref)
|
||||||
method["responses"].setdefault("403", generic_error.ref)
|
method["responses"].setdefault("403", generic_error.ref)
|
||||||
|
|
||||||
result["components"] = generator.registry.build(
|
result["components"] = generator.registry.build(spectacular_settings.APPEND_COMPONENTS)
|
||||||
spectacular_settings.APPEND_COMPONENTS
|
|
||||||
)
|
|
||||||
|
|
||||||
# This is a workaround for authentik/stages/prompt/stage.py
|
# This is a workaround for authentik/stages/prompt/stage.py
|
||||||
# since the serializer PromptChallengeResponse
|
# since the serializer PromptChallengeResponse
|
||||||
|
19
authentik/api/tasks.py
Normal file
19
authentik/api/tasks.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
"""API tasks"""
|
||||||
|
|
||||||
|
from authentik.lib.utils.http import get_http_session
|
||||||
|
from authentik.root.celery import CELERY_APP
|
||||||
|
|
||||||
|
SENTRY_SESSION = get_http_session()
|
||||||
|
|
||||||
|
|
||||||
|
@CELERY_APP.task()
|
||||||
|
def sentry_proxy(payload: str):
|
||||||
|
"""Relay data to sentry"""
|
||||||
|
SENTRY_SESSION.post(
|
||||||
|
"https://sentry.beryju.org/api/8/envelope/",
|
||||||
|
data=payload,
|
||||||
|
headers={
|
||||||
|
"Content-Type": "application/octet-stream",
|
||||||
|
},
|
||||||
|
timeout=10,
|
||||||
|
)
|
@ -1,12 +1,14 @@
|
|||||||
"""Test API Authentication"""
|
"""Test API Authentication"""
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.test import TestCase
|
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.authentication import token_from_header
|
from authentik.api.authentication import bearer_auth
|
||||||
from authentik.core.models import Token, TokenIntents
|
from authentik.core.models import USER_ATTRIBUTE_SA, Token, TokenIntents
|
||||||
|
from authentik.outposts.managed import OutpostManager
|
||||||
|
|
||||||
|
|
||||||
class TestAPIAuth(TestCase):
|
class TestAPIAuth(TestCase):
|
||||||
@ -14,36 +16,41 @@ class TestAPIAuth(TestCase):
|
|||||||
|
|
||||||
def test_valid_basic(self):
|
def test_valid_basic(self):
|
||||||
"""Test valid token"""
|
"""Test valid token"""
|
||||||
token = Token.objects.create(
|
token = Token.objects.create(intent=TokenIntents.INTENT_API, user=get_anonymous_user())
|
||||||
intent=TokenIntents.INTENT_API, user=get_anonymous_user()
|
|
||||||
)
|
|
||||||
auth = b64encode(f":{token.key}".encode()).decode()
|
auth = b64encode(f":{token.key}".encode()).decode()
|
||||||
self.assertEqual(token_from_header(f"Basic {auth}".encode()), token)
|
self.assertEqual(bearer_auth(f"Basic {auth}".encode()), token.user)
|
||||||
|
|
||||||
def test_valid_bearer(self):
|
def test_valid_bearer(self):
|
||||||
"""Test valid token"""
|
"""Test valid token"""
|
||||||
token = Token.objects.create(
|
token = Token.objects.create(intent=TokenIntents.INTENT_API, user=get_anonymous_user())
|
||||||
intent=TokenIntents.INTENT_API, user=get_anonymous_user()
|
self.assertEqual(bearer_auth(f"Bearer {token.key}".encode()), token.user)
|
||||||
)
|
|
||||||
self.assertEqual(token_from_header(f"Bearer {token.key}".encode()), token)
|
|
||||||
|
|
||||||
def test_invalid_type(self):
|
def test_invalid_type(self):
|
||||||
"""Test invalid type"""
|
"""Test invalid type"""
|
||||||
with self.assertRaises(AuthenticationFailed):
|
with self.assertRaises(AuthenticationFailed):
|
||||||
token_from_header("foo bar".encode())
|
bearer_auth("foo bar".encode())
|
||||||
|
|
||||||
def test_invalid_decode(self):
|
def test_invalid_decode(self):
|
||||||
"""Test invalid bas64"""
|
"""Test invalid bas64"""
|
||||||
with self.assertRaises(AuthenticationFailed):
|
with self.assertRaises(AuthenticationFailed):
|
||||||
token_from_header("Basic bar".encode())
|
bearer_auth("Basic bar".encode())
|
||||||
|
|
||||||
def test_invalid_empty_password(self):
|
def test_invalid_empty_password(self):
|
||||||
"""Test invalid with empty password"""
|
"""Test invalid with empty password"""
|
||||||
with self.assertRaises(AuthenticationFailed):
|
with self.assertRaises(AuthenticationFailed):
|
||||||
token_from_header("Basic :".encode())
|
bearer_auth("Basic :".encode())
|
||||||
|
|
||||||
def test_invalid_no_token(self):
|
def test_invalid_no_token(self):
|
||||||
"""Test invalid with no token"""
|
"""Test invalid with no token"""
|
||||||
with self.assertRaises(AuthenticationFailed):
|
with self.assertRaises(AuthenticationFailed):
|
||||||
auth = b64encode(":abc".encode()).decode()
|
auth = b64encode(":abc".encode()).decode()
|
||||||
self.assertIsNone(token_from_header(f"Basic :{auth}".encode()))
|
self.assertIsNone(bearer_auth(f"Basic :{auth}".encode()))
|
||||||
|
|
||||||
|
def test_managed_outpost(self):
|
||||||
|
"""Test managed outpost"""
|
||||||
|
with self.assertRaises(AuthenticationFailed):
|
||||||
|
user = bearer_auth(f"Bearer {settings.SECRET_KEY}".encode())
|
||||||
|
|
||||||
|
OutpostManager().run()
|
||||||
|
user = bearer_auth(f"Bearer {settings.SECRET_KEY}".encode())
|
||||||
|
self.assertEqual(user.attributes[USER_ATTRIBUTE_SA], True)
|
||||||
|
18
authentik/api/throttle.py
Normal file
18
authentik/api/throttle.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
"""Throttling classes"""
|
||||||
|
from typing import Type
|
||||||
|
|
||||||
|
from django.views import View
|
||||||
|
from rest_framework.request import Request
|
||||||
|
from rest_framework.throttling import ScopedRateThrottle
|
||||||
|
|
||||||
|
|
||||||
|
class SessionThrottle(ScopedRateThrottle):
|
||||||
|
"""Throttle based on session key"""
|
||||||
|
|
||||||
|
def allow_request(self, request: Request, view):
|
||||||
|
if request._request.user.is_superuser:
|
||||||
|
return True
|
||||||
|
return super().allow_request(request, view)
|
||||||
|
|
||||||
|
def get_cache_key(self, request: Request, view: Type[View]) -> str:
|
||||||
|
return f"authentik-throttle-session-{request._request.session.session_key}"
|
@ -1,8 +1,10 @@
|
|||||||
"""authentik api urls"""
|
"""authentik api urls"""
|
||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
|
|
||||||
from authentik.api.v2.urls import urlpatterns as v2_urls
|
from authentik.api.v3.urls import urlpatterns as v3_urls
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("v2beta/", include(v2_urls)),
|
# Remove in 2022.1
|
||||||
|
path("v2beta/", include(v3_urls)),
|
||||||
|
path("v3/", include(v3_urls)),
|
||||||
]
|
]
|
||||||
|
@ -5,7 +5,7 @@ from django.conf import settings
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from drf_spectacular.utils import extend_schema
|
from drf_spectacular.utils import extend_schema
|
||||||
from kubernetes.config.incluster_config import SERVICE_HOST_ENV_NAME
|
from kubernetes.config.incluster_config import SERVICE_HOST_ENV_NAME
|
||||||
from rest_framework.fields import BooleanField, CharField, ChoiceField, ListField
|
from rest_framework.fields import BooleanField, CharField, ChoiceField, IntegerField, 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
|
||||||
@ -33,6 +33,11 @@ class ConfigSerializer(PassiveSerializer):
|
|||||||
|
|
||||||
capabilities = ListField(child=ChoiceField(choices=Capabilities.choices))
|
capabilities = ListField(child=ChoiceField(choices=Capabilities.choices))
|
||||||
|
|
||||||
|
cache_timeout = IntegerField(required=True)
|
||||||
|
cache_timeout_flows = IntegerField(required=True)
|
||||||
|
cache_timeout_policies = IntegerField(required=True)
|
||||||
|
cache_timeout_reputation = IntegerField(required=True)
|
||||||
|
|
||||||
|
|
||||||
class ConfigView(APIView):
|
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"""
|
||||||
@ -58,13 +63,17 @@ class ConfigView(APIView):
|
|||||||
|
|
||||||
@extend_schema(responses={200: ConfigSerializer(many=False)})
|
@extend_schema(responses={200: ConfigSerializer(many=False)})
|
||||||
def get(self, request: Request) -> Response:
|
def get(self, request: Request) -> Response:
|
||||||
"""Retrive public configuration options"""
|
"""Retrieve public configuration options"""
|
||||||
config = ConfigSerializer(
|
config = ConfigSerializer(
|
||||||
{
|
{
|
||||||
"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"),
|
||||||
"capabilities": self.get_capabilities(),
|
"capabilities": self.get_capabilities(),
|
||||||
|
"cache_timeout": int(CONFIG.y("redis.cache_timeout")),
|
||||||
|
"cache_timeout_flows": int(CONFIG.y("redis.cache_timeout_flows")),
|
||||||
|
"cache_timeout_policies": int(CONFIG.y("redis.cache_timeout_policies")),
|
||||||
|
"cache_timeout_reputation": int(CONFIG.y("redis.cache_timeout_reputation")),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return Response(config.data)
|
return Response(config.data)
|
65
authentik/api/v3/sentry.py
Normal file
65
authentik/api/v3/sentry.py
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
"""Sentry tunnel"""
|
||||||
|
from json import loads
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.http.request import HttpRequest
|
||||||
|
from django.http.response import HttpResponse
|
||||||
|
from rest_framework.authentication import SessionAuthentication
|
||||||
|
from rest_framework.parsers import BaseParser
|
||||||
|
from rest_framework.permissions import AllowAny
|
||||||
|
from rest_framework.request import Request
|
||||||
|
from rest_framework.throttling import AnonRateThrottle
|
||||||
|
from rest_framework.views import APIView
|
||||||
|
from structlog.stdlib import get_logger
|
||||||
|
|
||||||
|
from authentik.api.tasks import sentry_proxy
|
||||||
|
from authentik.lib.config import CONFIG
|
||||||
|
|
||||||
|
LOGGER = get_logger()
|
||||||
|
|
||||||
|
|
||||||
|
class PlainTextParser(BaseParser):
|
||||||
|
"""Plain text parser."""
|
||||||
|
|
||||||
|
media_type = "text/plain"
|
||||||
|
|
||||||
|
def parse(self, stream, media_type=None, parser_context=None) -> str:
|
||||||
|
"""Simply return a string representing the body of the request."""
|
||||||
|
return stream.read()
|
||||||
|
|
||||||
|
|
||||||
|
class CsrfExemptSessionAuthentication(SessionAuthentication):
|
||||||
|
"""CSRF-exempt Session authentication"""
|
||||||
|
|
||||||
|
def enforce_csrf(self, request: Request):
|
||||||
|
return # To not perform the csrf check previously happening
|
||||||
|
|
||||||
|
|
||||||
|
class SentryTunnelView(APIView):
|
||||||
|
"""Sentry tunnel, to prevent ad blockers from blocking sentry"""
|
||||||
|
|
||||||
|
serializer_class = None
|
||||||
|
parser_classes = [PlainTextParser]
|
||||||
|
throttle_classes = [AnonRateThrottle]
|
||||||
|
permission_classes = [AllowAny]
|
||||||
|
authentication_classes = [CsrfExemptSessionAuthentication]
|
||||||
|
|
||||||
|
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):
|
||||||
|
LOGGER.debug("error reporting disabled")
|
||||||
|
return HttpResponse(status=400)
|
||||||
|
# Body is 2 json objects separated by \n
|
||||||
|
full_body = request.body
|
||||||
|
lines = full_body.splitlines()
|
||||||
|
if len(lines) < 1:
|
||||||
|
return HttpResponse(status=400)
|
||||||
|
header = loads(lines[0])
|
||||||
|
# Check that the DSN is what we expect
|
||||||
|
dsn = header.get("dsn", "")
|
||||||
|
if dsn != settings.SENTRY_DSN:
|
||||||
|
LOGGER.debug("Invalid dsn", have=dsn, expected=settings.SENTRY_DSN)
|
||||||
|
return HttpResponse(status=400)
|
||||||
|
sentry_proxy.delay(full_body.decode())
|
||||||
|
return HttpResponse(status=204)
|
@ -1,5 +1,6 @@
|
|||||||
"""api v2 urls"""
|
"""api v3 urls"""
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
from django.views.decorators.cache import cache_page
|
||||||
from drf_spectacular.views import SpectacularAPIView
|
from drf_spectacular.views import SpectacularAPIView
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
|
|
||||||
@ -9,25 +10,29 @@ 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 VersionView
|
from authentik.admin.api.version import VersionView
|
||||||
from authentik.admin.api.workers import WorkerView
|
from authentik.admin.api.workers import WorkerView
|
||||||
from authentik.api.v2.config import ConfigView
|
from authentik.api.v3.config import ConfigView
|
||||||
|
from authentik.api.v3.sentry import SentryTunnelView
|
||||||
from authentik.api.views import APIBrowserView
|
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.authenticated_sessions import AuthenticatedSessionViewSet
|
||||||
|
from authentik.core.api.devices import DeviceViewSet
|
||||||
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
|
||||||
from authentik.core.api.sources import SourceViewSet
|
from authentik.core.api.sources import SourceViewSet, UserSourceConnectionViewSet
|
||||||
from authentik.core.api.tokens import TokenViewSet
|
from authentik.core.api.tokens import TokenViewSet
|
||||||
from authentik.core.api.users import UserViewSet
|
from authentik.core.api.users import UserViewSet
|
||||||
from authentik.crypto.api import CertificateKeyPairViewSet
|
from authentik.crypto.api import CertificateKeyPairViewSet
|
||||||
from authentik.events.api.event import EventViewSet
|
from authentik.events.api.event import EventViewSet
|
||||||
from authentik.events.api.notification import NotificationViewSet
|
from authentik.events.api.notification import NotificationViewSet
|
||||||
|
from authentik.events.api.notification_mapping import NotificationWebhookMappingViewSet
|
||||||
from authentik.events.api.notification_rule import NotificationRuleViewSet
|
from authentik.events.api.notification_rule import NotificationRuleViewSet
|
||||||
from authentik.events.api.notification_transport import NotificationTransportViewSet
|
from authentik.events.api.notification_transport import NotificationTransportViewSet
|
||||||
from authentik.flows.api.bindings import FlowStageBindingViewSet
|
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.executor import FlowExecutorView
|
||||||
|
from authentik.flows.views.inspector import FlowInspectorView
|
||||||
from authentik.outposts.api.outposts import OutpostViewSet
|
from authentik.outposts.api.outposts import OutpostViewSet
|
||||||
from authentik.outposts.api.service_connections import (
|
from authentik.outposts.api.service_connections import (
|
||||||
DockerServiceConnectionViewSet,
|
DockerServiceConnectionViewSet,
|
||||||
@ -50,27 +55,25 @@ from authentik.policies.reputation.api import (
|
|||||||
from authentik.providers.ldap.api import LDAPOutpostConfigViewSet, LDAPProviderViewSet
|
from authentik.providers.ldap.api import LDAPOutpostConfigViewSet, LDAPProviderViewSet
|
||||||
from authentik.providers.oauth2.api.provider import OAuth2ProviderViewSet
|
from authentik.providers.oauth2.api.provider import OAuth2ProviderViewSet
|
||||||
from authentik.providers.oauth2.api.scope import ScopeMappingViewSet
|
from authentik.providers.oauth2.api.scope import ScopeMappingViewSet
|
||||||
from authentik.providers.oauth2.api.tokens import (
|
from authentik.providers.oauth2.api.tokens import AuthorizationCodeViewSet, RefreshTokenViewSet
|
||||||
AuthorizationCodeViewSet,
|
from authentik.providers.proxy.api import ProxyOutpostConfigViewSet, ProxyProviderViewSet
|
||||||
RefreshTokenViewSet,
|
|
||||||
)
|
|
||||||
from authentik.providers.proxy.api import (
|
|
||||||
ProxyOutpostConfigViewSet,
|
|
||||||
ProxyProviderViewSet,
|
|
||||||
)
|
|
||||||
from authentik.providers.saml.api import SAMLPropertyMappingViewSet, SAMLProviderViewSet
|
from authentik.providers.saml.api import SAMLPropertyMappingViewSet, SAMLProviderViewSet
|
||||||
from authentik.sources.ldap.api import LDAPPropertyMappingViewSet, LDAPSourceViewSet
|
from authentik.sources.ldap.api import LDAPPropertyMappingViewSet, LDAPSourceViewSet
|
||||||
from authentik.sources.oauth.api.source import OAuthSourceViewSet
|
from authentik.sources.oauth.api.source import OAuthSourceViewSet
|
||||||
from authentik.sources.oauth.api.source_connection import (
|
from authentik.sources.oauth.api.source_connection import UserOAuthSourceConnectionViewSet
|
||||||
UserOAuthSourceConnectionViewSet,
|
from authentik.sources.plex.api.source import PlexSourceViewSet
|
||||||
)
|
from authentik.sources.plex.api.source_connection import PlexSourceConnectionViewSet
|
||||||
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 (
|
from authentik.stages.authenticator_duo.api import (
|
||||||
AuthenticatorDuoStageViewSet,
|
AuthenticatorDuoStageViewSet,
|
||||||
DuoAdminDeviceViewSet,
|
DuoAdminDeviceViewSet,
|
||||||
DuoDeviceViewSet,
|
DuoDeviceViewSet,
|
||||||
)
|
)
|
||||||
|
from authentik.stages.authenticator_sms.api import (
|
||||||
|
AuthenticatorSMSStageViewSet,
|
||||||
|
SMSAdminDeviceViewSet,
|
||||||
|
SMSDeviceViewSet,
|
||||||
|
)
|
||||||
from authentik.stages.authenticator_static.api import (
|
from authentik.stages.authenticator_static.api import (
|
||||||
AuthenticatorStaticStageViewSet,
|
AuthenticatorStaticStageViewSet,
|
||||||
StaticAdminDeviceViewSet,
|
StaticAdminDeviceViewSet,
|
||||||
@ -81,9 +84,7 @@ from authentik.stages.authenticator_totp.api import (
|
|||||||
TOTPAdminDeviceViewSet,
|
TOTPAdminDeviceViewSet,
|
||||||
TOTPDeviceViewSet,
|
TOTPDeviceViewSet,
|
||||||
)
|
)
|
||||||
from authentik.stages.authenticator_validate.api import (
|
from authentik.stages.authenticator_validate.api import AuthenticatorValidateStageViewSet
|
||||||
AuthenticatorValidateStageViewSet,
|
|
||||||
)
|
|
||||||
from authentik.stages.authenticator_webauthn.api import (
|
from authentik.stages.authenticator_webauthn.api import (
|
||||||
AuthenticateWebAuthnStageViewSet,
|
AuthenticateWebAuthnStageViewSet,
|
||||||
WebAuthnAdminDeviceViewSet,
|
WebAuthnAdminDeviceViewSet,
|
||||||
@ -105,6 +106,7 @@ from authentik.stages.user_write.api import UserWriteStageViewSet
|
|||||||
from authentik.tenants.api import TenantViewSet
|
from authentik.tenants.api import TenantViewSet
|
||||||
|
|
||||||
router = routers.DefaultRouter()
|
router = routers.DefaultRouter()
|
||||||
|
router.include_format_suffixes = False
|
||||||
|
|
||||||
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")
|
||||||
@ -120,9 +122,7 @@ router.register("core/tenants", TenantViewSet)
|
|||||||
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)
|
||||||
router.register(
|
router.register("outposts/service_connections/kubernetes", KubernetesServiceConnectionViewSet)
|
||||||
"outposts/service_connections/kubernetes", KubernetesServiceConnectionViewSet
|
|
||||||
)
|
|
||||||
router.register("outposts/proxy", ProxyOutpostConfigViewSet)
|
router.register("outposts/proxy", ProxyOutpostConfigViewSet)
|
||||||
router.register("outposts/ldap", LDAPOutpostConfigViewSet)
|
router.register("outposts/ldap", LDAPOutpostConfigViewSet)
|
||||||
|
|
||||||
@ -137,7 +137,9 @@ router.register("events/transports", NotificationTransportViewSet)
|
|||||||
router.register("events/rules", NotificationRuleViewSet)
|
router.register("events/rules", NotificationRuleViewSet)
|
||||||
|
|
||||||
router.register("sources/all", SourceViewSet)
|
router.register("sources/all", SourceViewSet)
|
||||||
router.register("sources/oauth_user_connections", UserOAuthSourceConnectionViewSet)
|
router.register("sources/user_connections/all", UserSourceConnectionViewSet)
|
||||||
|
router.register("sources/user_connections/oauth", UserOAuthSourceConnectionViewSet)
|
||||||
|
router.register("sources/user_connections/plex", PlexSourceConnectionViewSet)
|
||||||
router.register("sources/ldap", LDAPSourceViewSet)
|
router.register("sources/ldap", LDAPSourceViewSet)
|
||||||
router.register("sources/saml", SAMLSourceViewSet)
|
router.register("sources/saml", SAMLSourceViewSet)
|
||||||
router.register("sources/oauth", OAuthSourceViewSet)
|
router.register("sources/oauth", OAuthSourceViewSet)
|
||||||
@ -167,8 +169,11 @@ router.register("propertymappings/all", PropertyMappingViewSet)
|
|||||||
router.register("propertymappings/ldap", LDAPPropertyMappingViewSet)
|
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("propertymappings/notification", NotificationWebhookMappingViewSet)
|
||||||
|
|
||||||
|
router.register("authenticators/all", DeviceViewSet, basename="device")
|
||||||
router.register("authenticators/duo", DuoDeviceViewSet)
|
router.register("authenticators/duo", DuoDeviceViewSet)
|
||||||
|
router.register("authenticators/sms", SMSDeviceViewSet)
|
||||||
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)
|
||||||
@ -177,14 +182,17 @@ router.register(
|
|||||||
DuoAdminDeviceViewSet,
|
DuoAdminDeviceViewSet,
|
||||||
basename="admin-duodevice",
|
basename="admin-duodevice",
|
||||||
)
|
)
|
||||||
|
router.register(
|
||||||
|
"authenticators/admin/sms",
|
||||||
|
SMSAdminDeviceViewSet,
|
||||||
|
basename="admin-smsdevice",
|
||||||
|
)
|
||||||
router.register(
|
router.register(
|
||||||
"authenticators/admin/static",
|
"authenticators/admin/static",
|
||||||
StaticAdminDeviceViewSet,
|
StaticAdminDeviceViewSet,
|
||||||
basename="admin-staticdevice",
|
basename="admin-staticdevice",
|
||||||
)
|
)
|
||||||
router.register(
|
router.register("authenticators/admin/totp", TOTPAdminDeviceViewSet, basename="admin-totpdevice")
|
||||||
"authenticators/admin/totp", TOTPAdminDeviceViewSet, basename="admin-totpdevice"
|
|
||||||
)
|
|
||||||
router.register(
|
router.register(
|
||||||
"authenticators/admin/webauthn",
|
"authenticators/admin/webauthn",
|
||||||
WebAuthnAdminDeviceViewSet,
|
WebAuthnAdminDeviceViewSet,
|
||||||
@ -193,6 +201,7 @@ router.register(
|
|||||||
|
|
||||||
router.register("stages/all", StageViewSet)
|
router.register("stages/all", StageViewSet)
|
||||||
router.register("stages/authenticator/duo", AuthenticatorDuoStageViewSet)
|
router.register("stages/authenticator/duo", AuthenticatorDuoStageViewSet)
|
||||||
|
router.register("stages/authenticator/sms", AuthenticatorSMSStageViewSet)
|
||||||
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)
|
||||||
@ -235,6 +244,12 @@ urlpatterns = (
|
|||||||
FlowExecutorView.as_view(),
|
FlowExecutorView.as_view(),
|
||||||
name="flow-executor",
|
name="flow-executor",
|
||||||
),
|
),
|
||||||
path("schema/", SpectacularAPIView.as_view(), name="schema"),
|
path(
|
||||||
|
"flows/inspector/<slug:flow_slug>/",
|
||||||
|
FlowInspectorView.as_view(),
|
||||||
|
name="flow-inspector",
|
||||||
|
),
|
||||||
|
path("sentry/", SentryTunnelView.as_view(), name="sentry"),
|
||||||
|
path("schema/", cache_page(86400)(SpectacularAPIView.as_view()), name="schema"),
|
||||||
]
|
]
|
||||||
)
|
)
|
@ -4,14 +4,9 @@ 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_spectacular.types import OpenApiTypes
|
from drf_spectacular.types import OpenApiTypes
|
||||||
from drf_spectacular.utils import (
|
from drf_spectacular.utils import OpenApiParameter, OpenApiResponse, extend_schema
|
||||||
OpenApiParameter,
|
|
||||||
OpenApiResponse,
|
|
||||||
extend_schema,
|
|
||||||
inline_serializer,
|
|
||||||
)
|
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.fields import BooleanField, CharField, FileField, ReadOnlyField
|
from rest_framework.fields import 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
|
||||||
@ -24,6 +19,7 @@ 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.api.used_by import UsedByMixin
|
from authentik.core.api.used_by import UsedByMixin
|
||||||
|
from authentik.core.api.utils import FilePathSerializer, FileUploadSerializer
|
||||||
from authentik.core.models import Application, User
|
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.api.exec import PolicyTestResultSerializer
|
||||||
@ -71,7 +67,7 @@ class ApplicationSerializer(ModelSerializer):
|
|||||||
class ApplicationViewSet(UsedByMixin, ModelViewSet):
|
class ApplicationViewSet(UsedByMixin, ModelViewSet):
|
||||||
"""Application Viewset"""
|
"""Application Viewset"""
|
||||||
|
|
||||||
queryset = Application.objects.all()
|
queryset = Application.objects.all().prefetch_related("provider")
|
||||||
serializer_class = ApplicationSerializer
|
serializer_class = ApplicationSerializer
|
||||||
search_fields = [
|
search_fields = [
|
||||||
"name",
|
"name",
|
||||||
@ -114,23 +110,26 @@ class ApplicationViewSet(UsedByMixin, ModelViewSet):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
@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)
|
||||||
# If the current user is superuser, they can set `for_user`
|
# If the current user is superuser, they can set `for_user`
|
||||||
for_user = self.request.user
|
for_user = request.user
|
||||||
if self.request.user.is_superuser and "for_user" in request.data:
|
if request.user.is_superuser and "for_user" in request.query_params:
|
||||||
for_user = get_object_or_404(User, pk=request.data.get("for_user"))
|
try:
|
||||||
engine = PolicyEngine(application, for_user, self.request)
|
for_user = get_object_or_404(User, pk=request.query_params.get("for_user"))
|
||||||
|
except ValueError:
|
||||||
|
return HttpResponseBadRequest("for_user must be numerical")
|
||||||
|
engine = PolicyEngine(application, for_user, request)
|
||||||
|
engine.use_cache = False
|
||||||
engine.build()
|
engine.build()
|
||||||
result = engine.result
|
result = engine.result
|
||||||
response = PolicyTestResultSerializer(PolicyResult(False))
|
response = PolicyTestResultSerializer(PolicyResult(False))
|
||||||
if result.passing:
|
if result.passing:
|
||||||
response = PolicyTestResultSerializer(PolicyResult(True))
|
response = PolicyTestResultSerializer(PolicyResult(True))
|
||||||
if self.request.user.is_superuser:
|
if request.user.is_superuser:
|
||||||
response = PolicyTestResultSerializer(result)
|
response = PolicyTestResultSerializer(result)
|
||||||
return Response(response.data)
|
return Response(response.data)
|
||||||
|
|
||||||
@ -145,19 +144,19 @@ class ApplicationViewSet(UsedByMixin, ModelViewSet):
|
|||||||
)
|
)
|
||||||
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"""
|
||||||
|
should_cache = request.GET.get("search", "") == ""
|
||||||
|
|
||||||
|
superuser_full_list = str(request.GET.get("superuser_full_list", "false")).lower() == "true"
|
||||||
|
if superuser_full_list and request.user.is_superuser:
|
||||||
|
return super().list(request)
|
||||||
|
|
||||||
|
# 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)
|
self.request.session.pop(USER_LOGIN_AUTHENTICATED, None)
|
||||||
queryset = self._filter_queryset_for_list(self.get_queryset())
|
queryset = self._filter_queryset_for_list(self.get_queryset())
|
||||||
self.paginate_queryset(queryset)
|
self.paginate_queryset(queryset)
|
||||||
|
|
||||||
should_cache = request.GET.get("search", "") == ""
|
|
||||||
|
|
||||||
superuser_full_list = (
|
|
||||||
str(request.GET.get("superuser_full_list", "false")).lower() == "true"
|
|
||||||
)
|
|
||||||
if superuser_full_list and request.user.is_superuser:
|
|
||||||
serializer = self.get_serializer(queryset, many=True)
|
|
||||||
return self.get_paginated_response(serializer.data)
|
|
||||||
|
|
||||||
allowed_applications = []
|
allowed_applications = []
|
||||||
if not should_cache:
|
if not should_cache:
|
||||||
allowed_applications = self._get_allowed_applications(queryset)
|
allowed_applications = self._get_allowed_applications(queryset)
|
||||||
@ -177,13 +176,7 @@ class ApplicationViewSet(UsedByMixin, ModelViewSet):
|
|||||||
@permission_required("authentik_core.change_application")
|
@permission_required("authentik_core.change_application")
|
||||||
@extend_schema(
|
@extend_schema(
|
||||||
request={
|
request={
|
||||||
"multipart/form-data": inline_serializer(
|
"multipart/form-data": FileUploadSerializer,
|
||||||
"SetIcon",
|
|
||||||
fields={
|
|
||||||
"file": FileField(required=False),
|
|
||||||
"clear": BooleanField(default=False),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
responses={
|
responses={
|
||||||
200: OpenApiResponse(description="Success"),
|
200: OpenApiResponse(description="Success"),
|
||||||
@ -215,7 +208,7 @@ class ApplicationViewSet(UsedByMixin, ModelViewSet):
|
|||||||
|
|
||||||
@permission_required("authentik_core.change_application")
|
@permission_required("authentik_core.change_application")
|
||||||
@extend_schema(
|
@extend_schema(
|
||||||
request=inline_serializer("SetIconURL", fields={"url": CharField()}),
|
request=FilePathSerializer,
|
||||||
responses={
|
responses={
|
||||||
200: OpenApiResponse(description="Success"),
|
200: OpenApiResponse(description="Success"),
|
||||||
400: OpenApiResponse(description="Bad request"),
|
400: OpenApiResponse(description="Bad request"),
|
||||||
@ -238,9 +231,7 @@ class ApplicationViewSet(UsedByMixin, ModelViewSet):
|
|||||||
app.save()
|
app.save()
|
||||||
return Response({})
|
return Response({})
|
||||||
|
|
||||||
@permission_required(
|
@permission_required("authentik_core.view_application", ["authentik_events.view_event"])
|
||||||
"authentik_core.view_application", ["authentik_events.view_event"]
|
|
||||||
)
|
|
||||||
@extend_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
|
||||||
|
@ -11,6 +11,7 @@ from rest_framework.serializers import ModelSerializer
|
|||||||
from rest_framework.viewsets import GenericViewSet
|
from rest_framework.viewsets import GenericViewSet
|
||||||
from ua_parser import user_agent_parser
|
from ua_parser import user_agent_parser
|
||||||
|
|
||||||
|
from authentik.api.authorization import OwnerSuperuserPermissions
|
||||||
from authentik.core.api.used_by import UsedByMixin
|
from authentik.core.api.used_by import UsedByMixin
|
||||||
from authentik.core.models import AuthenticatedSession
|
from authentik.core.models import AuthenticatedSession
|
||||||
from authentik.events.geo import GEOIP_READER, GeoIPDict
|
from authentik.events.geo import GEOIP_READER, GeoIPDict
|
||||||
@ -68,9 +69,7 @@ class AuthenticatedSessionSerializer(ModelSerializer):
|
|||||||
"""Get parsed user agent"""
|
"""Get parsed user agent"""
|
||||||
return user_agent_parser.Parse(instance.last_user_agent)
|
return user_agent_parser.Parse(instance.last_user_agent)
|
||||||
|
|
||||||
def get_geo_ip(
|
def get_geo_ip(self, instance: AuthenticatedSession) -> Optional[GeoIPDict]: # pragma: no cover
|
||||||
self, instance: AuthenticatedSession
|
|
||||||
) -> Optional[GeoIPDict]: # pragma: no cover
|
|
||||||
"""Get parsed user agent"""
|
"""Get parsed user agent"""
|
||||||
return GEOIP_READER.city_dict(instance.last_ip)
|
return GEOIP_READER.city_dict(instance.last_ip)
|
||||||
|
|
||||||
@ -104,11 +103,8 @@ class AuthenticatedSessionViewSet(
|
|||||||
search_fields = ["user__username", "last_ip", "last_user_agent"]
|
search_fields = ["user__username", "last_ip", "last_user_agent"]
|
||||||
filterset_fields = ["user__username", "last_ip", "last_user_agent"]
|
filterset_fields = ["user__username", "last_ip", "last_user_agent"]
|
||||||
ordering = ["user__username"]
|
ordering = ["user__username"]
|
||||||
filter_backends = [
|
permission_classes = [OwnerSuperuserPermissions]
|
||||||
DjangoFilterBackend,
|
filter_backends = [DjangoFilterBackend, OrderingFilter, SearchFilter]
|
||||||
OrderingFilter,
|
|
||||||
SearchFilter,
|
|
||||||
]
|
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
user = self.request.user if self.request else get_anonymous_user()
|
user = self.request.user if self.request else get_anonymous_user()
|
||||||
|
36
authentik/core/api/devices.py
Normal file
36
authentik/core/api/devices.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
"""Authenticator Devices API Views"""
|
||||||
|
from django_otp import devices_for_user
|
||||||
|
from django_otp.models import Device
|
||||||
|
from drf_spectacular.utils import extend_schema
|
||||||
|
from rest_framework.fields import CharField, IntegerField, SerializerMethodField
|
||||||
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
from rest_framework.request import Request
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from rest_framework.viewsets import ViewSet
|
||||||
|
|
||||||
|
from authentik.core.api.utils import MetaNameSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class DeviceSerializer(MetaNameSerializer):
|
||||||
|
"""Serializer for Duo authenticator devices"""
|
||||||
|
|
||||||
|
pk = IntegerField()
|
||||||
|
name = CharField()
|
||||||
|
type = SerializerMethodField()
|
||||||
|
|
||||||
|
def get_type(self, instance: Device) -> str:
|
||||||
|
"""Get type of device"""
|
||||||
|
return instance._meta.label
|
||||||
|
|
||||||
|
|
||||||
|
class DeviceViewSet(ViewSet):
|
||||||
|
"""Viewset for authenticator devices"""
|
||||||
|
|
||||||
|
serializer_class = DeviceSerializer
|
||||||
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
|
@extend_schema(responses={200: DeviceSerializer(many=True)})
|
||||||
|
def list(self, request: Request) -> Response:
|
||||||
|
"""Get all devices for current user"""
|
||||||
|
devices = devices_for_user(request.user)
|
||||||
|
return Response(DeviceSerializer(devices, many=True).data)
|
@ -1,33 +1,88 @@
|
|||||||
"""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 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.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"""
|
||||||
|
|
||||||
|
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",
|
||||||
|
"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 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):
|
class GroupViewSet(UsedByMixin, ModelViewSet):
|
||||||
"""Group Viewset"""
|
"""Group Viewset"""
|
||||||
|
|
||||||
queryset = Group.objects.all()
|
queryset = Group.objects.all().select_related("parent").prefetch_related("users")
|
||||||
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:
|
||||||
|
@ -15,11 +15,7 @@ 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.used_by import UsedByMixin
|
||||||
from authentik.core.api.utils import (
|
from authentik.core.api.utils import MetaNameSerializer, PassiveSerializer, TypeCreateSerializer
|
||||||
MetaNameSerializer,
|
|
||||||
PassiveSerializer,
|
|
||||||
TypeCreateSerializer,
|
|
||||||
)
|
|
||||||
from authentik.core.expression import PropertyMappingEvaluator
|
from authentik.core.expression import PropertyMappingEvaluator
|
||||||
from authentik.core.models import PropertyMapping
|
from authentik.core.models import PropertyMapping
|
||||||
from authentik.lib.utils.reflection import all_subclasses
|
from authentik.lib.utils.reflection import all_subclasses
|
||||||
@ -141,9 +137,7 @@ class PropertyMappingViewSet(
|
|||||||
self.request,
|
self.request,
|
||||||
**test_params.validated_data.get("context", {}),
|
**test_params.validated_data.get("context", {}),
|
||||||
)
|
)
|
||||||
response_data["result"] = dumps(
|
response_data["result"] = dumps(result, indent=(4 if format_result else None))
|
||||||
result, indent=(4 if format_result else None)
|
|
||||||
)
|
|
||||||
except Exception as exc: # pylint: disable=broad-except
|
except Exception as exc: # pylint: disable=broad-except
|
||||||
response_data["result"] = str(exc)
|
response_data["result"] = str(exc)
|
||||||
response_data["successful"] = False
|
response_data["successful"] = False
|
||||||
|
@ -1,18 +1,21 @@
|
|||||||
"""Source API Views"""
|
"""Source API Views"""
|
||||||
from typing import Iterable
|
from typing import Iterable
|
||||||
|
|
||||||
|
from django_filters.rest_framework import DjangoFilterBackend
|
||||||
from drf_spectacular.utils import extend_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.filters import OrderingFilter, SearchFilter
|
||||||
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, SerializerMethodField
|
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.api.authorization import OwnerFilter, OwnerPermissions
|
||||||
from authentik.core.api.used_by import UsedByMixin
|
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, UserSourceConnection
|
||||||
from authentik.core.types import UserSettingSerializer
|
from authentik.core.types import UserSettingSerializer
|
||||||
from authentik.lib.utils.reflection import all_subclasses
|
from authentik.lib.utils.reflection import all_subclasses
|
||||||
from authentik.policies.engine import PolicyEngine
|
from authentik.policies.engine import PolicyEngine
|
||||||
@ -74,6 +77,8 @@ class SourceViewSet(
|
|||||||
for subclass in all_subclasses(self.queryset.model):
|
for subclass in all_subclasses(self.queryset.model):
|
||||||
subclass: Source
|
subclass: Source
|
||||||
component = ""
|
component = ""
|
||||||
|
if len(subclass.__subclasses__()) > 0:
|
||||||
|
continue
|
||||||
if subclass._meta.abstract:
|
if subclass._meta.abstract:
|
||||||
component = subclass.__bases__[0]().component
|
component = subclass.__bases__[0]().component
|
||||||
else:
|
else:
|
||||||
@ -93,9 +98,9 @@ class SourceViewSet(
|
|||||||
@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"""
|
||||||
_all_sources: Iterable[Source] = Source.objects.filter(
|
_all_sources: Iterable[Source] = (
|
||||||
enabled=True
|
Source.objects.filter(enabled=True).select_subclasses().order_by("name")
|
||||||
).select_subclasses()
|
)
|
||||||
matching_sources: list[UserSettingSerializer] = []
|
matching_sources: list[UserSettingSerializer] = []
|
||||||
for source in _all_sources:
|
for source in _all_sources:
|
||||||
user_settings = source.ui_user_settings
|
user_settings = source.ui_user_settings
|
||||||
@ -111,3 +116,39 @@ class SourceViewSet(
|
|||||||
LOGGER.warning(source_settings.errors)
|
LOGGER.warning(source_settings.errors)
|
||||||
matching_sources.append(source_settings.validated_data)
|
matching_sources.append(source_settings.validated_data)
|
||||||
return Response(matching_sources)
|
return Response(matching_sources)
|
||||||
|
|
||||||
|
|
||||||
|
class UserSourceConnectionSerializer(SourceSerializer):
|
||||||
|
"""OAuth Source Serializer"""
|
||||||
|
|
||||||
|
source = SourceSerializer(read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = UserSourceConnection
|
||||||
|
fields = [
|
||||||
|
"pk",
|
||||||
|
"user",
|
||||||
|
"source",
|
||||||
|
"created",
|
||||||
|
]
|
||||||
|
extra_kwargs = {
|
||||||
|
"user": {"read_only": True},
|
||||||
|
"created": {"read_only": True},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class UserSourceConnectionViewSet(
|
||||||
|
mixins.RetrieveModelMixin,
|
||||||
|
mixins.UpdateModelMixin,
|
||||||
|
mixins.DestroyModelMixin,
|
||||||
|
UsedByMixin,
|
||||||
|
mixins.ListModelMixin,
|
||||||
|
GenericViewSet,
|
||||||
|
):
|
||||||
|
"""User-source connection Viewset"""
|
||||||
|
|
||||||
|
queryset = UserSourceConnection.objects.all()
|
||||||
|
serializer_class = UserSourceConnectionSerializer
|
||||||
|
permission_classes = [OwnerPermissions]
|
||||||
|
filter_backends = [OwnerFilter, DjangoFilterBackend, OrderingFilter, SearchFilter]
|
||||||
|
ordering = ["pk"]
|
||||||
|
@ -1,18 +1,25 @@
|
|||||||
"""Tokens API Viewset"""
|
"""Tokens API Viewset"""
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from django.http.response import Http404
|
from django.http.response import Http404
|
||||||
|
from django_filters.rest_framework import DjangoFilterBackend
|
||||||
from drf_spectacular.utils import OpenApiResponse, extend_schema
|
from drf_spectacular.utils import OpenApiResponse, extend_schema
|
||||||
|
from guardian.shortcuts import get_anonymous_user
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
|
from rest_framework.exceptions import ValidationError
|
||||||
from rest_framework.fields import CharField
|
from rest_framework.fields import CharField
|
||||||
|
from rest_framework.filters import OrderingFilter, SearchFilter
|
||||||
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 ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
|
from authentik.api.authorization import OwnerSuperuserPermissions
|
||||||
from authentik.api.decorators import permission_required
|
from authentik.api.decorators import permission_required
|
||||||
from authentik.core.api.used_by import UsedByMixin
|
from authentik.core.api.used_by import UsedByMixin
|
||||||
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
|
||||||
|
|
||||||
@ -20,7 +27,16 @@ from authentik.managed.api import ManagedSerializer
|
|||||||
class TokenSerializer(ManagedSerializer, ModelSerializer):
|
class TokenSerializer(ManagedSerializer, ModelSerializer):
|
||||||
"""Token Serializer"""
|
"""Token Serializer"""
|
||||||
|
|
||||||
user = UserSerializer(required=False)
|
user_obj = UserSerializer(required=False, source="user")
|
||||||
|
|
||||||
|
def validate(self, attrs: dict[Any, str]) -> dict[Any, str]:
|
||||||
|
"""Ensure only API or App password tokens are created."""
|
||||||
|
request: Request = self.context["request"]
|
||||||
|
attrs.setdefault("user", request.user)
|
||||||
|
attrs.setdefault("intent", TokenIntents.INTENT_API)
|
||||||
|
if attrs.get("intent") not in [TokenIntents.INTENT_API, TokenIntents.INTENT_APP_PASSWORD]:
|
||||||
|
raise ValidationError(f"Invalid intent {attrs.get('intent')}")
|
||||||
|
return attrs
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
||||||
@ -31,11 +47,14 @@ class TokenSerializer(ManagedSerializer, ModelSerializer):
|
|||||||
"identifier",
|
"identifier",
|
||||||
"intent",
|
"intent",
|
||||||
"user",
|
"user",
|
||||||
|
"user_obj",
|
||||||
"description",
|
"description",
|
||||||
"expires",
|
"expires",
|
||||||
"expiring",
|
"expiring",
|
||||||
]
|
]
|
||||||
depth = 2
|
extra_kwargs = {
|
||||||
|
"user": {"required": False},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class TokenViewSerializer(PassiveSerializer):
|
class TokenViewSerializer(PassiveSerializer):
|
||||||
@ -48,7 +67,7 @@ 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",
|
||||||
@ -61,11 +80,27 @@ class TokenViewSet(UsedByMixin, ModelViewSet):
|
|||||||
"intent",
|
"intent",
|
||||||
"user__username",
|
"user__username",
|
||||||
"description",
|
"description",
|
||||||
|
"expires",
|
||||||
|
"expiring",
|
||||||
|
"managed",
|
||||||
]
|
]
|
||||||
ordering = ["expires"]
|
ordering = ["identifier", "expires"]
|
||||||
|
permission_classes = [OwnerSuperuserPermissions]
|
||||||
|
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)
|
||||||
|
|
||||||
def perform_create(self, serializer: TokenSerializer):
|
def perform_create(self, serializer: TokenSerializer):
|
||||||
serializer.save(user=self.request.user, intent=TokenIntents.INTENT_API)
|
if not self.request.user.is_superuser:
|
||||||
|
return serializer.save(
|
||||||
|
user=self.request.user,
|
||||||
|
expiring=self.request.user.attributes.get(USER_ATTRIBUTE_TOKEN_EXPIRING, True),
|
||||||
|
)
|
||||||
|
return super().perform_create(serializer)
|
||||||
|
|
||||||
@permission_required("authentik_core.view_token_key")
|
@permission_required("authentik_core.view_token_key")
|
||||||
@extend_schema(
|
@extend_schema(
|
||||||
@ -81,7 +116,5 @@ class TokenViewSet(UsedByMixin, ModelViewSet):
|
|||||||
token: Token = self.get_object()
|
token: Token = self.get_object()
|
||||||
if token.is_expired:
|
if token.is_expired:
|
||||||
raise Http404
|
raise Http404
|
||||||
Event.new(EventAction.SECRET_VIEW, secret=token).from_http( # noqa # nosec
|
Event.new(EventAction.SECRET_VIEW, secret=token).from_http(request) # noqa # nosec
|
||||||
request
|
|
||||||
)
|
|
||||||
return Response(TokenViewSerializer({"key": token.key}).data)
|
return Response(TokenViewSerializer({"key": token.key}).data)
|
||||||
|
@ -79,9 +79,7 @@ class UsedByMixin:
|
|||||||
).all():
|
).all():
|
||||||
# Only merge shadows on first object
|
# Only merge shadows on first object
|
||||||
if first_object:
|
if first_object:
|
||||||
shadows += getattr(
|
shadows += getattr(manager.model._meta, "authentik_used_by_shadows", [])
|
||||||
manager.model._meta, "authentik_used_by_shadows", []
|
|
||||||
)
|
|
||||||
first_object = False
|
first_object = False
|
||||||
serializer = UsedBySerializer(
|
serializer = UsedBySerializer(
|
||||||
data={
|
data={
|
||||||
|
@ -1,39 +1,67 @@
|
|||||||
"""User API Views"""
|
"""User API Views"""
|
||||||
|
from datetime import timedelta
|
||||||
from json import loads
|
from json import loads
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
|
from django.db.transaction import atomic
|
||||||
|
from django.db.utils import IntegrityError
|
||||||
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.utils.text import slugify
|
||||||
|
from django.utils.timezone import now
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
|
from django_filters.filters import BooleanFilter, CharFilter, ModelMultipleChoiceFilter
|
||||||
from django_filters.filterset import FilterSet
|
from django_filters.filterset import FilterSet
|
||||||
from drf_spectacular.utils import extend_schema, extend_schema_field
|
from drf_spectacular.types import OpenApiTypes
|
||||||
from guardian.utils import get_anonymous_user
|
from drf_spectacular.utils import (
|
||||||
|
OpenApiParameter,
|
||||||
|
extend_schema,
|
||||||
|
extend_schema_field,
|
||||||
|
inline_serializer,
|
||||||
|
)
|
||||||
|
from guardian.shortcuts import get_anonymous_user, get_objects_for_user
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.fields import CharField, JSONField, SerializerMethodField
|
from rest_framework.fields import CharField, DictField, JSONField, SerializerMethodField
|
||||||
|
from rest_framework.permissions import IsAuthenticated
|
||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.serializers import (
|
from rest_framework.serializers import (
|
||||||
BooleanField,
|
BooleanField,
|
||||||
ListSerializer,
|
ListSerializer,
|
||||||
ModelSerializer,
|
ModelSerializer,
|
||||||
|
PrimaryKeyRelatedField,
|
||||||
|
Serializer,
|
||||||
ValidationError,
|
ValidationError,
|
||||||
)
|
)
|
||||||
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 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.groups import GroupSerializer
|
from authentik.core.api.groups import GroupSerializer
|
||||||
from authentik.core.api.used_by import UsedByMixin
|
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_USER
|
||||||
SESSION_IMPERSONATE_ORIGINAL_USER,
|
from authentik.core.models import (
|
||||||
SESSION_IMPERSONATE_USER,
|
USER_ATTRIBUTE_CHANGE_EMAIL,
|
||||||
|
USER_ATTRIBUTE_CHANGE_USERNAME,
|
||||||
|
USER_ATTRIBUTE_SA,
|
||||||
|
USER_ATTRIBUTE_TOKEN_EXPIRING,
|
||||||
|
Group,
|
||||||
|
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.stages.email.models import EmailStage
|
||||||
|
from authentik.stages.email.tasks import send_mails
|
||||||
|
from authentik.stages.email.utils import TemplateEmailMessage
|
||||||
from authentik.tenants.models import Tenant
|
from authentik.tenants.models import Tenant
|
||||||
|
|
||||||
|
LOGGER = get_logger()
|
||||||
|
|
||||||
|
|
||||||
class UserSerializer(ModelSerializer):
|
class UserSerializer(ModelSerializer):
|
||||||
"""User Serializer"""
|
"""User Serializer"""
|
||||||
@ -41,7 +69,10 @@ class UserSerializer(ModelSerializer):
|
|||||||
is_superuser = BooleanField(read_only=True)
|
is_superuser = BooleanField(read_only=True)
|
||||||
avatar = CharField(read_only=True)
|
avatar = CharField(read_only=True)
|
||||||
attributes = JSONField(validators=[is_dict], required=False)
|
attributes = JSONField(validators=[is_dict], required=False)
|
||||||
groups = ListSerializer(child=GroupSerializer(), read_only=True, source="ak_groups")
|
groups = PrimaryKeyRelatedField(
|
||||||
|
allow_empty=True, many=True, source="ak_groups", queryset=Group.objects.all()
|
||||||
|
)
|
||||||
|
groups_obj = ListSerializer(child=GroupSerializer(), read_only=True, source="ak_groups")
|
||||||
uid = CharField(read_only=True)
|
uid = CharField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -55,19 +86,86 @@ class UserSerializer(ModelSerializer):
|
|||||||
"last_login",
|
"last_login",
|
||||||
"is_superuser",
|
"is_superuser",
|
||||||
"groups",
|
"groups",
|
||||||
|
"groups_obj",
|
||||||
"email",
|
"email",
|
||||||
"avatar",
|
"avatar",
|
||||||
"attributes",
|
"attributes",
|
||||||
"uid",
|
"uid",
|
||||||
]
|
]
|
||||||
|
extra_kwargs = {
|
||||||
|
"name": {"allow_blank": True},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 = SerializerMethodField()
|
||||||
|
uid = CharField(read_only=True)
|
||||||
|
settings = DictField(source="attributes.settings", default=dict)
|
||||||
|
|
||||||
|
@extend_schema_field(
|
||||||
|
ListSerializer(
|
||||||
|
child=inline_serializer(
|
||||||
|
"UserSelfGroups",
|
||||||
|
{"name": CharField(read_only=True), "pk": CharField(read_only=True)},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
def get_groups(self, _: User):
|
||||||
|
"""Return only the group names a user is member of"""
|
||||||
|
for group in self.instance.ak_groups.all():
|
||||||
|
yield {
|
||||||
|
"name": group.name,
|
||||||
|
"pk": group.pk,
|
||||||
|
}
|
||||||
|
|
||||||
|
def validate_email(self, email: str):
|
||||||
|
"""Check if the user is allowed to change their email"""
|
||||||
|
if self.instance.group_attributes().get(USER_ATTRIBUTE_CHANGE_EMAIL, True):
|
||||||
|
return email
|
||||||
|
if email != self.instance.email:
|
||||||
|
raise ValidationError("Not allowed to change email.")
|
||||||
|
return email
|
||||||
|
|
||||||
|
def validate_username(self, username: str):
|
||||||
|
"""Check if the user is allowed to change their username"""
|
||||||
|
if self.instance.group_attributes().get(USER_ATTRIBUTE_CHANGE_USERNAME, True):
|
||||||
|
return username
|
||||||
|
if username != self.instance.username:
|
||||||
|
raise ValidationError("Not allowed to change username.")
|
||||||
|
return username
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
|
||||||
|
model = User
|
||||||
|
fields = [
|
||||||
|
"pk",
|
||||||
|
"username",
|
||||||
|
"name",
|
||||||
|
"is_active",
|
||||||
|
"is_superuser",
|
||||||
|
"groups",
|
||||||
|
"email",
|
||||||
|
"avatar",
|
||||||
|
"uid",
|
||||||
|
"settings",
|
||||||
|
]
|
||||||
|
extra_kwargs = {
|
||||||
|
"is_active": {"read_only": True},
|
||||||
|
"name": {"allow_blank": 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):
|
||||||
@ -87,17 +185,13 @@ class UserMetricsSerializer(PassiveSerializer):
|
|||||||
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"]
|
||||||
return get_events_per_1h(
|
return get_events_per_1h(action=EventAction.LOGIN_FAILED, context__username=user.username)
|
||||||
action=EventAction.LOGIN_FAILED, context__username=user.username
|
|
||||||
)
|
|
||||||
|
|
||||||
@extend_schema_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"]
|
||||||
return get_events_per_1h(
|
return get_events_per_1h(action=EventAction.AUTHORIZE_APPLICATION, user__pk=user.pk)
|
||||||
action=EventAction.AUTHORIZE_APPLICATION, user__pk=user.pk
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class UsersFilter(FilterSet):
|
class UsersFilter(FilterSet):
|
||||||
@ -112,6 +206,16 @@ class UsersFilter(FilterSet):
|
|||||||
|
|
||||||
is_superuser = BooleanFilter(field_name="ak_groups", lookup_expr="is_superuser")
|
is_superuser = BooleanFilter(field_name="ak_groups", lookup_expr="is_superuser")
|
||||||
|
|
||||||
|
groups_by_name = ModelMultipleChoiceFilter(
|
||||||
|
field_name="ak_groups__name",
|
||||||
|
to_field_name="name",
|
||||||
|
queryset=Group.objects.all(),
|
||||||
|
)
|
||||||
|
groups_by_pk = ModelMultipleChoiceFilter(
|
||||||
|
field_name="ak_groups",
|
||||||
|
queryset=Group.objects.all(),
|
||||||
|
)
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def filter_attributes(self, queryset, name, value):
|
def filter_attributes(self, queryset, name, value):
|
||||||
"""Filter attributes by query args"""
|
"""Filter attributes by query args"""
|
||||||
@ -128,34 +232,131 @@ 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",
|
||||||
|
"groups_by_name",
|
||||||
|
"groups_by_pk",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class UserViewSet(UsedByMixin, ModelViewSet):
|
class UserViewSet(UsedByMixin, ModelViewSet):
|
||||||
"""User Viewset"""
|
"""User Viewset"""
|
||||||
|
|
||||||
queryset = User.objects.none()
|
queryset = User.objects.none()
|
||||||
|
ordering = ["username"]
|
||||||
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): # pragma: no cover
|
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)
|
||||||
|
|
||||||
|
def _create_recovery_link(self) -> tuple[Optional[str], Optional[Token]]:
|
||||||
|
"""Create a recovery link (when the current tenant has a recovery flow set),
|
||||||
|
that can either be shown to an admin or sent to the user directly"""
|
||||||
|
tenant: Tenant = self.request._request.tenant
|
||||||
|
# Check that there is a recovery flow, if not return an error
|
||||||
|
flow = tenant.flow_recovery
|
||||||
|
if not flow:
|
||||||
|
LOGGER.debug("No recovery flow set")
|
||||||
|
return None, None
|
||||||
|
user: User = self.get_object()
|
||||||
|
token, __ = Token.objects.get_or_create(
|
||||||
|
identifier=f"{user.uid}-password-reset",
|
||||||
|
user=user,
|
||||||
|
intent=TokenIntents.INTENT_RECOVERY,
|
||||||
|
)
|
||||||
|
querystring = urlencode({"token": token.key})
|
||||||
|
link = self.request.build_absolute_uri(
|
||||||
|
reverse_lazy("authentik_core:if-flow", kwargs={"flow_slug": flow.slug})
|
||||||
|
+ f"?{querystring}"
|
||||||
|
)
|
||||||
|
return link, token
|
||||||
|
|
||||||
|
@permission_required(None, ["authentik_core.add_user", "authentik_core.add_token"])
|
||||||
|
@extend_schema(
|
||||||
|
request=inline_serializer(
|
||||||
|
"UserServiceAccountSerializer",
|
||||||
|
{
|
||||||
|
"name": CharField(required=True),
|
||||||
|
"create_group": BooleanField(default=False),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
responses={
|
||||||
|
200: inline_serializer(
|
||||||
|
"UserServiceAccountResponse",
|
||||||
|
{
|
||||||
|
"username": CharField(required=True),
|
||||||
|
"token": CharField(required=True),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
@action(detail=False, methods=["POST"], pagination_class=None, filter_backends=[])
|
||||||
|
def service_account(self, request: Request) -> Response:
|
||||||
|
"""Create a new user account that is marked as a service account"""
|
||||||
|
username = request.data.get("name")
|
||||||
|
create_group = request.data.get("create_group", False)
|
||||||
|
with atomic():
|
||||||
|
try:
|
||||||
|
user = User.objects.create(
|
||||||
|
username=username,
|
||||||
|
name=username,
|
||||||
|
attributes={USER_ATTRIBUTE_SA: True, USER_ATTRIBUTE_TOKEN_EXPIRING: False},
|
||||||
|
)
|
||||||
|
if create_group:
|
||||||
|
group = Group.objects.create(
|
||||||
|
name=username,
|
||||||
|
)
|
||||||
|
group.users.add(user)
|
||||||
|
token = Token.objects.create(
|
||||||
|
identifier=slugify(f"service-account-{username}-password"),
|
||||||
|
intent=TokenIntents.INTENT_APP_PASSWORD,
|
||||||
|
user=user,
|
||||||
|
expires=now() + timedelta(days=360),
|
||||||
|
)
|
||||||
|
return Response({"username": user.username, "token": token.key})
|
||||||
|
except (IntegrityError) as exc:
|
||||||
|
return Response(data={"non_field_errors": [str(exc)]}, status=400)
|
||||||
|
|
||||||
@extend_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:
|
||||||
"""Get information about current user"""
|
"""Get information about current user"""
|
||||||
serializer = SessionUserSerializer(
|
serializer = SessionUserSerializer(
|
||||||
data={"user": UserSerializer(request.user).data}
|
data={"user": UserSelfSerializer(instance=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]
|
instance=request._request.session[SESSION_IMPERSONATE_ORIGINAL_USER]
|
||||||
).data
|
).data
|
||||||
serializer.is_valid()
|
return Response(serializer.initial_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, status=400)
|
||||||
|
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 Response({"user": data.data})
|
||||||
|
|
||||||
@permission_required("authentik_core.view_user", ["authentik_events.view_event"])
|
@permission_required("authentik_core.view_user", ["authentik_events.view_event"])
|
||||||
@extend_schema(responses={200: UserMetricsSerializer(many=False)})
|
@extend_schema(responses={200: UserMetricsSerializer(many=False)})
|
||||||
@ -179,24 +380,60 @@ class UserViewSet(UsedByMixin, ModelViewSet):
|
|||||||
# 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
|
link, _ = self._create_recovery_link()
|
||||||
# Check that there is a recovery flow, if not return an error
|
if not link:
|
||||||
flow = tenant.flow_recovery
|
LOGGER.debug("Couldn't create token")
|
||||||
if not flow:
|
|
||||||
return Response({"link": ""}, status=404)
|
return Response({"link": ""}, status=404)
|
||||||
user: User = self.get_object()
|
|
||||||
token, __ = Token.objects.get_or_create(
|
|
||||||
identifier=f"{user.uid}-password-reset",
|
|
||||||
user=user,
|
|
||||||
intent=TokenIntents.INTENT_RECOVERY,
|
|
||||||
)
|
|
||||||
querystring = urlencode({"token": token.key})
|
|
||||||
link = request.build_absolute_uri(
|
|
||||||
reverse_lazy("authentik_core:if-flow", kwargs={"flow_slug": flow.slug})
|
|
||||||
+ f"?{querystring}"
|
|
||||||
)
|
|
||||||
return Response({"link": link})
|
return Response({"link": link})
|
||||||
|
|
||||||
|
@permission_required("authentik_core.reset_user_password")
|
||||||
|
@extend_schema(
|
||||||
|
parameters=[
|
||||||
|
OpenApiParameter(
|
||||||
|
name="email_stage",
|
||||||
|
location=OpenApiParameter.QUERY,
|
||||||
|
type=OpenApiTypes.STR,
|
||||||
|
required=True,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
responses={
|
||||||
|
"204": Serializer(),
|
||||||
|
"404": Serializer(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
@action(detail=True, pagination_class=None, filter_backends=[])
|
||||||
|
# pylint: disable=invalid-name, unused-argument
|
||||||
|
def recovery_email(self, request: Request, pk: int) -> Response:
|
||||||
|
"""Create a temporary link that a user can use to recover their accounts"""
|
||||||
|
for_user = self.get_object()
|
||||||
|
if for_user.email == "":
|
||||||
|
LOGGER.debug("User doesn't have an email address")
|
||||||
|
return Response(status=404)
|
||||||
|
link, token = self._create_recovery_link()
|
||||||
|
if not link:
|
||||||
|
LOGGER.debug("Couldn't create token")
|
||||||
|
return Response(status=404)
|
||||||
|
# Lookup the email stage to assure the current user can access it
|
||||||
|
stages = get_objects_for_user(
|
||||||
|
request.user, "authentik_stages_email.view_emailstage"
|
||||||
|
).filter(pk=request.query_params.get("email_stage"))
|
||||||
|
if not stages.exists():
|
||||||
|
LOGGER.debug("Email stage does not exist/user has no permissions")
|
||||||
|
return Response(status=404)
|
||||||
|
email_stage: EmailStage = stages.first()
|
||||||
|
message = TemplateEmailMessage(
|
||||||
|
subject=_(email_stage.subject),
|
||||||
|
template_name=email_stage.template,
|
||||||
|
to=[for_user.email],
|
||||||
|
template_context={
|
||||||
|
"url": link,
|
||||||
|
"user": for_user,
|
||||||
|
"expires": token.expires,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
send_mails(email_stage, message)
|
||||||
|
return Response(status=204)
|
||||||
|
|
||||||
def _filter_queryset_for_list(self, queryset: QuerySet) -> QuerySet:
|
def _filter_queryset_for_list(self, queryset: QuerySet) -> QuerySet:
|
||||||
"""Custom filter_queryset method which ignores guardian, but still supports sorting"""
|
"""Custom filter_queryset method which ignores guardian, but still supports sorting"""
|
||||||
for backend in list(self.filter_backends):
|
for backend in list(self.filter_backends):
|
||||||
@ -206,6 +443,6 @@ class UserViewSet(UsedByMixin, 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)
|
||||||
|
@ -2,21 +2,15 @@
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from django.db.models import Model
|
from django.db.models import Model
|
||||||
from rest_framework.fields import CharField, IntegerField
|
from rest_framework.fields import BooleanField, CharField, FileField, IntegerField
|
||||||
from rest_framework.serializers import (
|
from rest_framework.serializers import Serializer, SerializerMethodField, ValidationError
|
||||||
Serializer,
|
|
||||||
SerializerMethodField,
|
|
||||||
ValidationError,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def is_dict(value: Any):
|
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(
|
raise ValidationError("Value must be a dictionary, and not have any duplicate keys.")
|
||||||
"Value must be a dictionary, and not have any duplicate keys."
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class PassiveSerializer(Serializer):
|
class PassiveSerializer(Serializer):
|
||||||
@ -25,13 +19,21 @@ class PassiveSerializer(Serializer):
|
|||||||
def create(self, validated_data: dict) -> Model: # pragma: no cover
|
def create(self, validated_data: dict) -> Model: # pragma: no cover
|
||||||
return Model()
|
return Model()
|
||||||
|
|
||||||
def update(
|
def update(self, instance: Model, validated_data: dict) -> Model: # pragma: no cover
|
||||||
self, instance: Model, validated_data: dict
|
|
||||||
) -> Model: # pragma: no cover
|
|
||||||
return Model()
|
return Model()
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Model
|
class FileUploadSerializer(PassiveSerializer):
|
||||||
|
"""Serializer to upload file"""
|
||||||
|
|
||||||
|
file = FileField(required=False)
|
||||||
|
clear = BooleanField(default=False)
|
||||||
|
|
||||||
|
|
||||||
|
class FilePathSerializer(PassiveSerializer):
|
||||||
|
"""Serializer to upload file"""
|
||||||
|
|
||||||
|
url = CharField()
|
||||||
|
|
||||||
|
|
||||||
class MetaNameSerializer(PassiveSerializer):
|
class MetaNameSerializer(PassiveSerializer):
|
||||||
|
59
authentik/core/auth.py
Normal file
59
authentik/core/auth.py
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
"""Authenticate with tokens"""
|
||||||
|
|
||||||
|
from typing import Any, Optional
|
||||||
|
|
||||||
|
from django.contrib.auth.backends import ModelBackend
|
||||||
|
from django.http.request import HttpRequest
|
||||||
|
|
||||||
|
from authentik.core.models import Token, TokenIntents, User
|
||||||
|
from authentik.events.utils import cleanse_dict, sanitize_dict
|
||||||
|
from authentik.flows.planner import FlowPlan
|
||||||
|
from authentik.flows.views.executor import SESSION_KEY_PLAN
|
||||||
|
from authentik.stages.password.stage import PLAN_CONTEXT_METHOD, PLAN_CONTEXT_METHOD_ARGS
|
||||||
|
|
||||||
|
|
||||||
|
class InbuiltBackend(ModelBackend):
|
||||||
|
"""Inbuilt backend"""
|
||||||
|
|
||||||
|
def authenticate(
|
||||||
|
self, request: HttpRequest, username: Optional[str], password: Optional[str], **kwargs: Any
|
||||||
|
) -> Optional[User]:
|
||||||
|
user = super().authenticate(request, username=username, password=password, **kwargs)
|
||||||
|
if not user:
|
||||||
|
return None
|
||||||
|
self.set_method("password", request)
|
||||||
|
return user
|
||||||
|
|
||||||
|
def set_method(self, method: str, request: Optional[HttpRequest], **kwargs):
|
||||||
|
"""Set method data on current flow, if possbiel"""
|
||||||
|
if not request:
|
||||||
|
return
|
||||||
|
# Since we can't directly pass other variables to signals, and we want to log the method
|
||||||
|
# and the token used, we assume we're running in a flow and set a variable in the context
|
||||||
|
flow_plan: FlowPlan = request.session[SESSION_KEY_PLAN]
|
||||||
|
flow_plan.context[PLAN_CONTEXT_METHOD] = method
|
||||||
|
flow_plan.context[PLAN_CONTEXT_METHOD_ARGS] = cleanse_dict(sanitize_dict(kwargs))
|
||||||
|
request.session[SESSION_KEY_PLAN] = flow_plan
|
||||||
|
|
||||||
|
|
||||||
|
class TokenBackend(InbuiltBackend):
|
||||||
|
"""Authenticate with token"""
|
||||||
|
|
||||||
|
def authenticate(
|
||||||
|
self, request: HttpRequest, username: Optional[str], password: Optional[str], **kwargs: Any
|
||||||
|
) -> Optional[User]:
|
||||||
|
try:
|
||||||
|
user = User._default_manager.get_by_natural_key(username)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
# Run the default password hasher once to reduce the timing
|
||||||
|
# difference between an existing and a nonexistent user (#20760).
|
||||||
|
User().set_password(password)
|
||||||
|
return None
|
||||||
|
tokens = Token.filter_not_expired(
|
||||||
|
user=user, key=password, intent=TokenIntents.INTENT_APP_PASSWORD
|
||||||
|
)
|
||||||
|
if not tokens.exists():
|
||||||
|
return None
|
||||||
|
token = tokens.first()
|
||||||
|
self.set_method("password", request, token=token)
|
||||||
|
return token.user
|
@ -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.authentication import token_from_header
|
from authentik.api.authentication import bearer_auth
|
||||||
from authentik.core.models import User
|
from authentik.core.models import User
|
||||||
|
|
||||||
LOGGER = get_logger()
|
LOGGER = get_logger()
|
||||||
@ -24,12 +24,12 @@ class AuthJsonConsumer(JsonWebsocketConsumer):
|
|||||||
raw_header = headers[b"authorization"]
|
raw_header = headers[b"authorization"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
token = token_from_header(raw_header)
|
user = bearer_auth(raw_header)
|
||||||
# token is only None when no header was given, in which case we deny too
|
# user is only None when no header was given, in which case we deny too
|
||||||
if not token:
|
if not user:
|
||||||
raise DenyConnection()
|
raise DenyConnection()
|
||||||
except AuthenticationFailed as exc:
|
except AuthenticationFailed as exc:
|
||||||
LOGGER.warning("Failed to authenticate", exc=exc)
|
LOGGER.warning("Failed to authenticate", exc=exc)
|
||||||
raise DenyConnection()
|
raise DenyConnection()
|
||||||
|
|
||||||
self.user = token.user
|
self.user = user
|
||||||
|
@ -10,6 +10,9 @@ SESSION_IMPERSONATE_USER = "authentik_impersonate_user"
|
|||||||
SESSION_IMPERSONATE_ORIGINAL_USER = "authentik_impersonate_original_user"
|
SESSION_IMPERSONATE_ORIGINAL_USER = "authentik_impersonate_original_user"
|
||||||
LOCAL = local()
|
LOCAL = local()
|
||||||
RESPONSE_HEADER_ID = "X-authentik-id"
|
RESPONSE_HEADER_ID = "X-authentik-id"
|
||||||
|
KEY_AUTH_VIA = "auth_via"
|
||||||
|
KEY_USER = "user"
|
||||||
|
INTERNAL_HEADER_PREFIX = "X-authentik-internal-"
|
||||||
|
|
||||||
|
|
||||||
class ImpersonateMiddleware:
|
class ImpersonateMiddleware:
|
||||||
@ -50,15 +53,17 @@ class RequestIDMiddleware:
|
|||||||
}
|
}
|
||||||
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"]
|
if auth_via := LOCAL.authentik.get(KEY_AUTH_VIA, None):
|
||||||
del LOCAL.authentik["host"]
|
response[INTERNAL_HEADER_PREFIX + KEY_AUTH_VIA] = auth_via
|
||||||
|
response[INTERNAL_HEADER_PREFIX + KEY_USER] = request.user.username
|
||||||
|
for key in list(LOCAL.authentik.keys()):
|
||||||
|
del LOCAL.authentik[key]
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def structlog_add_request_id(logger: Logger, method_name: str, event_dict):
|
def structlog_add_request_id(logger: Logger, method_name: str, event_dict: 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.update(LOCAL.authentik)
|
||||||
event_dict["host"] = LOCAL.authentik.get("host", "")
|
|
||||||
return event_dict
|
return event_dict
|
||||||
|
@ -38,9 +38,7 @@ class Migration(migrations.Migration):
|
|||||||
("password", models.CharField(max_length=128, verbose_name="password")),
|
("password", models.CharField(max_length=128, verbose_name="password")),
|
||||||
(
|
(
|
||||||
"last_login",
|
"last_login",
|
||||||
models.DateTimeField(
|
models.DateTimeField(blank=True, null=True, verbose_name="last login"),
|
||||||
blank=True, null=True, verbose_name="last login"
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"is_superuser",
|
"is_superuser",
|
||||||
@ -53,35 +51,25 @@ class Migration(migrations.Migration):
|
|||||||
(
|
(
|
||||||
"username",
|
"username",
|
||||||
models.CharField(
|
models.CharField(
|
||||||
error_messages={
|
error_messages={"unique": "A user with that username already exists."},
|
||||||
"unique": "A user with that username already exists."
|
|
||||||
},
|
|
||||||
help_text="Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.",
|
help_text="Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.",
|
||||||
max_length=150,
|
max_length=150,
|
||||||
unique=True,
|
unique=True,
|
||||||
validators=[
|
validators=[django.contrib.auth.validators.UnicodeUsernameValidator()],
|
||||||
django.contrib.auth.validators.UnicodeUsernameValidator()
|
|
||||||
],
|
|
||||||
verbose_name="username",
|
verbose_name="username",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"first_name",
|
"first_name",
|
||||||
models.CharField(
|
models.CharField(blank=True, max_length=30, verbose_name="first name"),
|
||||||
blank=True, max_length=30, verbose_name="first name"
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"last_name",
|
"last_name",
|
||||||
models.CharField(
|
models.CharField(blank=True, max_length=150, verbose_name="last name"),
|
||||||
blank=True, max_length=150, verbose_name="last name"
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"email",
|
"email",
|
||||||
models.EmailField(
|
models.EmailField(blank=True, max_length=254, verbose_name="email address"),
|
||||||
blank=True, max_length=254, verbose_name="email address"
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"is_staff",
|
"is_staff",
|
||||||
@ -217,9 +205,7 @@ class Migration(migrations.Migration):
|
|||||||
),
|
),
|
||||||
(
|
(
|
||||||
"expires",
|
"expires",
|
||||||
models.DateTimeField(
|
models.DateTimeField(default=authentik.core.models.default_token_duration),
|
||||||
default=authentik.core.models.default_token_duration
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
("expiring", models.BooleanField(default=True)),
|
("expiring", models.BooleanField(default=True)),
|
||||||
("description", models.TextField(blank=True, default="")),
|
("description", models.TextField(blank=True, default="")),
|
||||||
@ -306,9 +292,7 @@ class Migration(migrations.Migration):
|
|||||||
("name", models.TextField(help_text="Application's display Name.")),
|
("name", models.TextField(help_text="Application's display Name.")),
|
||||||
(
|
(
|
||||||
"slug",
|
"slug",
|
||||||
models.SlugField(
|
models.SlugField(help_text="Internal application name, used in URLs."),
|
||||||
help_text="Internal application name, used in URLs."
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
("skip_authorization", models.BooleanField(default=False)),
|
("skip_authorization", models.BooleanField(default=False)),
|
||||||
("meta_launch_url", models.URLField(blank=True, default="")),
|
("meta_launch_url", models.URLField(blank=True, default="")),
|
||||||
|
@ -0,0 +1,221 @@
|
|||||||
|
# Generated by Django 3.2.8 on 2021-10-10 16:16
|
||||||
|
|
||||||
|
from os import environ
|
||||||
|
|
||||||
|
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 create_default_user(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
||||||
|
# We have to use a direct import here, otherwise we get an object manager error
|
||||||
|
from authentik.core.models import User
|
||||||
|
|
||||||
|
db_alias = schema_editor.connection.alias
|
||||||
|
|
||||||
|
akadmin, _ = User.objects.using(db_alias).get_or_create(
|
||||||
|
username="akadmin", email="root@localhost", name="authentik Default Admin"
|
||||||
|
)
|
||||||
|
if "TF_BUILD" in environ or "AK_ADMIN_PASS" in environ or settings.TEST:
|
||||||
|
akadmin.set_password(environ.get("AK_ADMIN_PASS", "akadmin"), signal=False) # noqa # nosec
|
||||||
|
else:
|
||||||
|
akadmin.set_unusable_password()
|
||||||
|
akadmin.save()
|
||||||
|
|
||||||
|
|
||||||
|
def create_default_admin_group(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
||||||
|
db_alias = schema_editor.connection.alias
|
||||||
|
Group = apps.get_model("authentik_core", "Group")
|
||||||
|
User = apps.get_model("authentik_core", "User")
|
||||||
|
|
||||||
|
# Creates a default admin group
|
||||||
|
group, _ = Group.objects.using(db_alias).get_or_create(
|
||||||
|
is_superuser=True,
|
||||||
|
defaults={
|
||||||
|
"name": "authentik Admins",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
group.users.set(User.objects.filter(username="akadmin"))
|
||||||
|
group.save()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
replaces = [
|
||||||
|
("authentik_core", "0002_auto_20200523_1133"),
|
||||||
|
("authentik_core", "0003_default_user"),
|
||||||
|
("authentik_core", "0004_auto_20200703_2213"),
|
||||||
|
("authentik_core", "0005_token_intent"),
|
||||||
|
("authentik_core", "0006_auto_20200709_1608"),
|
||||||
|
("authentik_core", "0007_auto_20200815_1841"),
|
||||||
|
("authentik_core", "0008_auto_20200824_1532"),
|
||||||
|
("authentik_core", "0009_group_is_superuser"),
|
||||||
|
("authentik_core", "0010_auto_20200917_1021"),
|
||||||
|
("authentik_core", "0011_provider_name_temp"),
|
||||||
|
]
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("authentik_core", "0001_initial"),
|
||||||
|
("authentik_flows", "0003_auto_20200523_1133"),
|
||||||
|
("auth", "0012_alter_user_first_name_max_length"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name="application",
|
||||||
|
name="skip_authorization",
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="source",
|
||||||
|
name="authentication_flow",
|
||||||
|
field=models.ForeignKey(
|
||||||
|
blank=True,
|
||||||
|
default=None,
|
||||||
|
help_text="Flow to use when authenticating existing users.",
|
||||||
|
null=True,
|
||||||
|
on_delete=django.db.models.deletion.SET_NULL,
|
||||||
|
related_name="source_authentication",
|
||||||
|
to="authentik_flows.flow",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="source",
|
||||||
|
name="enrollment_flow",
|
||||||
|
field=models.ForeignKey(
|
||||||
|
blank=True,
|
||||||
|
default=None,
|
||||||
|
help_text="Flow to use when enrolling new users.",
|
||||||
|
null=True,
|
||||||
|
on_delete=django.db.models.deletion.SET_NULL,
|
||||||
|
related_name="source_enrollment",
|
||||||
|
to="authentik_flows.flow",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="provider",
|
||||||
|
name="authorization_flow",
|
||||||
|
field=models.ForeignKey(
|
||||||
|
help_text="Flow used when authorizing this provider.",
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
related_name="provider_authorization",
|
||||||
|
to="authentik_flows.flow",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name="user",
|
||||||
|
name="is_superuser",
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name="user",
|
||||||
|
name="is_staff",
|
||||||
|
),
|
||||||
|
migrations.RunPython(
|
||||||
|
code=create_default_user,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="user",
|
||||||
|
name="is_superuser",
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="user",
|
||||||
|
name="is_staff",
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name="application",
|
||||||
|
options={"verbose_name": "Application", "verbose_name_plural": "Applications"},
|
||||||
|
),
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name="user",
|
||||||
|
options={
|
||||||
|
"permissions": (("reset_user_password", "Reset Password"),),
|
||||||
|
"verbose_name": "User",
|
||||||
|
"verbose_name_plural": "Users",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="token",
|
||||||
|
name="intent",
|
||||||
|
field=models.TextField(
|
||||||
|
choices=[("verification", "Intent Verification"), ("api", "Intent Api")],
|
||||||
|
default="verification",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="source",
|
||||||
|
name="slug",
|
||||||
|
field=models.SlugField(help_text="Internal source name, used in URLs.", unique=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="user",
|
||||||
|
name="first_name",
|
||||||
|
field=models.CharField(blank=True, max_length=150, verbose_name="first name"),
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name="user",
|
||||||
|
name="groups",
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="user",
|
||||||
|
name="groups",
|
||||||
|
field=models.ManyToManyField(
|
||||||
|
blank=True,
|
||||||
|
help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.",
|
||||||
|
related_name="user_set",
|
||||||
|
related_query_name="user",
|
||||||
|
to="auth.Group",
|
||||||
|
verbose_name="groups",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name="user",
|
||||||
|
name="is_superuser",
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name="user",
|
||||||
|
name="is_staff",
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="user",
|
||||||
|
name="pb_groups",
|
||||||
|
field=models.ManyToManyField(related_name="users", to="authentik_core.Group"),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="group",
|
||||||
|
name="is_superuser",
|
||||||
|
field=models.BooleanField(
|
||||||
|
default=False, help_text="Users added to this group will be superusers."
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.RunPython(
|
||||||
|
code=create_default_admin_group,
|
||||||
|
),
|
||||||
|
migrations.AlterModelManagers(
|
||||||
|
name="user",
|
||||||
|
managers=[
|
||||||
|
("objects", authentik.core.models.UserManager()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name="user",
|
||||||
|
options={
|
||||||
|
"permissions": (
|
||||||
|
("reset_user_password", "Reset Password"),
|
||||||
|
("impersonate", "Can impersonate other users"),
|
||||||
|
),
|
||||||
|
"verbose_name": "User",
|
||||||
|
"verbose_name_plural": "Users",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="provider",
|
||||||
|
name="name_temp",
|
||||||
|
field=models.TextField(default=""),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
@ -17,9 +17,7 @@ def create_default_user(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
|||||||
username="akadmin", email="root@localhost", name="authentik Default Admin"
|
username="akadmin", email="root@localhost", name="authentik Default Admin"
|
||||||
)
|
)
|
||||||
if "TF_BUILD" in environ or "AK_ADMIN_PASS" in environ or settings.TEST:
|
if "TF_BUILD" in environ or "AK_ADMIN_PASS" in environ or settings.TEST:
|
||||||
akadmin.set_password(
|
akadmin.set_password(environ.get("AK_ADMIN_PASS", "akadmin"), signal=False) # noqa # nosec
|
||||||
environ.get("AK_ADMIN_PASS", "akadmin"), signal=False
|
|
||||||
) # noqa # nosec
|
|
||||||
else:
|
else:
|
||||||
akadmin.set_unusable_password()
|
akadmin.set_unusable_password()
|
||||||
akadmin.save()
|
akadmin.save()
|
||||||
|
@ -13,8 +13,6 @@ class Migration(migrations.Migration):
|
|||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name="source",
|
model_name="source",
|
||||||
name="slug",
|
name="slug",
|
||||||
field=models.SlugField(
|
field=models.SlugField(help_text="Internal source name, used in URLs.", unique=True),
|
||||||
help_text="Internal source name, used in URLs.", unique=True
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
@ -13,8 +13,6 @@ class Migration(migrations.Migration):
|
|||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name="user",
|
model_name="user",
|
||||||
name="first_name",
|
name="first_name",
|
||||||
field=models.CharField(
|
field=models.CharField(blank=True, max_length=150, verbose_name="first name"),
|
||||||
blank=True, max_length=150, verbose_name="first name"
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
@ -40,9 +40,7 @@ class Migration(migrations.Migration):
|
|||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name="user",
|
model_name="user",
|
||||||
name="pb_groups",
|
name="pb_groups",
|
||||||
field=models.ManyToManyField(
|
field=models.ManyToManyField(related_name="users", to="authentik_core.Group"),
|
||||||
related_name="users", to="authentik_core.Group"
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name="group",
|
model_name="group",
|
||||||
|
@ -0,0 +1,118 @@
|
|||||||
|
# Generated by Django 3.2.8 on 2021-10-12 15:36
|
||||||
|
|
||||||
|
from django.apps.registry import Apps
|
||||||
|
from django.db import migrations, models
|
||||||
|
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
||||||
|
|
||||||
|
import authentik.core.models
|
||||||
|
|
||||||
|
|
||||||
|
def set_default_token_key(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
||||||
|
db_alias = schema_editor.connection.alias
|
||||||
|
Token = apps.get_model("authentik_core", "Token")
|
||||||
|
|
||||||
|
for token in Token.objects.using(db_alias).all():
|
||||||
|
token.key = token.pk.hex
|
||||||
|
token.save()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
replaces = [
|
||||||
|
("authentik_core", "0012_auto_20201003_1737"),
|
||||||
|
("authentik_core", "0013_auto_20201003_2132"),
|
||||||
|
("authentik_core", "0014_auto_20201018_1158"),
|
||||||
|
("authentik_core", "0015_application_icon"),
|
||||||
|
("authentik_core", "0016_auto_20201202_2234"),
|
||||||
|
]
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("authentik_providers_saml", "0006_remove_samlprovider_name"),
|
||||||
|
("authentik_providers_oauth2", "0006_remove_oauth2provider_name"),
|
||||||
|
("authentik_core", "0011_provider_name_temp"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name="provider",
|
||||||
|
old_name="name_temp",
|
||||||
|
new_name="name",
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="token",
|
||||||
|
name="identifier",
|
||||||
|
field=models.TextField(default=""),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="token",
|
||||||
|
name="intent",
|
||||||
|
field=models.TextField(
|
||||||
|
choices=[
|
||||||
|
("verification", "Intent Verification"),
|
||||||
|
("api", "Intent Api"),
|
||||||
|
("recovery", "Intent Recovery"),
|
||||||
|
],
|
||||||
|
default="verification",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AlterUniqueTogether(
|
||||||
|
name="token",
|
||||||
|
unique_together={("identifier", "user")},
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="token",
|
||||||
|
name="key",
|
||||||
|
field=models.TextField(default=authentik.core.models.default_token_key),
|
||||||
|
),
|
||||||
|
migrations.AlterUniqueTogether(
|
||||||
|
name="token",
|
||||||
|
unique_together=set(),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="token",
|
||||||
|
name="identifier",
|
||||||
|
field=models.SlugField(max_length=255),
|
||||||
|
),
|
||||||
|
migrations.AddIndex(
|
||||||
|
model_name="token",
|
||||||
|
index=models.Index(fields=["key"], name="authentik_co_key_e45007_idx"),
|
||||||
|
),
|
||||||
|
migrations.AddIndex(
|
||||||
|
model_name="token",
|
||||||
|
index=models.Index(fields=["identifier"], name="authentik_co_identif_1a34a8_idx"),
|
||||||
|
),
|
||||||
|
migrations.RunPython(
|
||||||
|
code=set_default_token_key,
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name="application",
|
||||||
|
name="meta_icon_url",
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="application",
|
||||||
|
name="meta_icon",
|
||||||
|
field=models.FileField(blank=True, default="", upload_to="application-icons/"),
|
||||||
|
),
|
||||||
|
migrations.RemoveIndex(
|
||||||
|
model_name="token",
|
||||||
|
name="authentik_co_key_e45007_idx",
|
||||||
|
),
|
||||||
|
migrations.RemoveIndex(
|
||||||
|
model_name="token",
|
||||||
|
name="authentik_co_identif_1a34a8_idx",
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name="user",
|
||||||
|
old_name="pb_groups",
|
||||||
|
new_name="ak_groups",
|
||||||
|
),
|
||||||
|
migrations.AddIndex(
|
||||||
|
model_name="token",
|
||||||
|
index=models.Index(fields=["identifier"], name="authentik_c_identif_d9d032_idx"),
|
||||||
|
),
|
||||||
|
migrations.AddIndex(
|
||||||
|
model_name="token",
|
||||||
|
index=models.Index(fields=["key"], name="authentik_c_key_f71355_idx"),
|
||||||
|
),
|
||||||
|
]
|
@ -42,9 +42,7 @@ class Migration(migrations.Migration):
|
|||||||
),
|
),
|
||||||
migrations.AddIndex(
|
migrations.AddIndex(
|
||||||
model_name="token",
|
model_name="token",
|
||||||
index=models.Index(
|
index=models.Index(fields=["identifier"], name="authentik_co_identif_1a34a8_idx"),
|
||||||
fields=["identifier"], name="authentik_co_identif_1a34a8_idx"
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
migrations.RunPython(set_default_token_key),
|
migrations.RunPython(set_default_token_key),
|
||||||
]
|
]
|
||||||
|
@ -17,8 +17,6 @@ class Migration(migrations.Migration):
|
|||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name="application",
|
model_name="application",
|
||||||
name="meta_icon",
|
name="meta_icon",
|
||||||
field=models.FileField(
|
field=models.FileField(blank=True, default="", upload_to="application-icons/"),
|
||||||
blank=True, default="", upload_to="application-icons/"
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
@ -25,9 +25,7 @@ class Migration(migrations.Migration):
|
|||||||
),
|
),
|
||||||
migrations.AddIndex(
|
migrations.AddIndex(
|
||||||
model_name="token",
|
model_name="token",
|
||||||
index=models.Index(
|
index=models.Index(fields=["identifier"], name="authentik_c_identif_d9d032_idx"),
|
||||||
fields=["identifier"], name="authentik_c_identif_d9d032_idx"
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
migrations.AddIndex(
|
migrations.AddIndex(
|
||||||
model_name="token",
|
model_name="token",
|
||||||
|
@ -0,0 +1,210 @@
|
|||||||
|
# Generated by Django 3.2.8 on 2021-10-10 16:12
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
from os import environ
|
||||||
|
|
||||||
|
import django.core.validators
|
||||||
|
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
|
||||||
|
from django.db.models import Count
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
|
||||||
|
def create_default_user_token(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
||||||
|
# We have to use a direct import here, otherwise we get an object manager error
|
||||||
|
from authentik.core.models import Token, TokenIntents, User
|
||||||
|
|
||||||
|
db_alias = schema_editor.connection.alias
|
||||||
|
|
||||||
|
akadmin = User.objects.using(db_alias).filter(username="akadmin")
|
||||||
|
if not akadmin.exists():
|
||||||
|
return
|
||||||
|
if "AK_ADMIN_TOKEN" not in environ:
|
||||||
|
return
|
||||||
|
Token.objects.using(db_alias).create(
|
||||||
|
identifier="authentik-boostrap-token",
|
||||||
|
user=akadmin.first(),
|
||||||
|
intent=TokenIntents.INTENT_API,
|
||||||
|
expiring=False,
|
||||||
|
key=environ["AK_ADMIN_TOKEN"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
replaces = [
|
||||||
|
("authentik_core", "0018_auto_20210330_1345"),
|
||||||
|
("authentik_core", "0019_source_managed"),
|
||||||
|
("authentik_core", "0020_source_user_matching_mode"),
|
||||||
|
("authentik_core", "0021_alter_application_slug"),
|
||||||
|
("authentik_core", "0022_authenticatedsession"),
|
||||||
|
("authentik_core", "0023_alter_application_meta_launch_url"),
|
||||||
|
("authentik_core", "0024_alter_token_identifier"),
|
||||||
|
("authentik_core", "0025_alter_application_meta_icon"),
|
||||||
|
("authentik_core", "0026_alter_application_meta_icon"),
|
||||||
|
("authentik_core", "0027_bootstrap_token"),
|
||||||
|
("authentik_core", "0028_alter_token_intent"),
|
||||||
|
]
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("authentik_core", "0017_managed"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name="token",
|
||||||
|
options={
|
||||||
|
"permissions": (("view_token_key", "View token's key"),),
|
||||||
|
"verbose_name": "Token",
|
||||||
|
"verbose_name_plural": "Tokens",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="source",
|
||||||
|
name="managed",
|
||||||
|
field=models.TextField(
|
||||||
|
default=None,
|
||||||
|
help_text="Objects which are managed by authentik. These objects are created and updated automatically. This is flag only indicates that an object can be overwritten by migrations. You can still modify the objects via the API, but expect changes to be overwritten in a later update.",
|
||||||
|
null=True,
|
||||||
|
unique=True,
|
||||||
|
verbose_name="Managed by authentik",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="source",
|
||||||
|
name="user_matching_mode",
|
||||||
|
field=models.TextField(
|
||||||
|
choices=[
|
||||||
|
("identifier", "Use the source-specific identifier"),
|
||||||
|
(
|
||||||
|
"email_link",
|
||||||
|
"Link to a user with identical email address. Can have security implications when a source doesn't validate email addresses.",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"email_deny",
|
||||||
|
"Use the user's email address, but deny enrollment when the email address already exists.",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"username_link",
|
||||||
|
"Link to a user with identical username. Can have security implications when a username is used with another source.",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"username_deny",
|
||||||
|
"Use the user's username, but deny enrollment when the username already exists.",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
default="identifier",
|
||||||
|
help_text="How the source determines if an existing user should be authenticated or a new user enrolled.",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="application",
|
||||||
|
name="slug",
|
||||||
|
field=models.SlugField(
|
||||||
|
help_text="Internal application name, used in URLs.", unique=True
|
||||||
|
),
|
||||||
|
),
|
||||||
|
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(
|
||||||
|
code=migrate_sessions,
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="application",
|
||||||
|
name="meta_launch_url",
|
||||||
|
field=models.TextField(
|
||||||
|
blank=True, default="", validators=[django.core.validators.URLValidator()]
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.RunPython(
|
||||||
|
code=fix_duplicates,
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="token",
|
||||||
|
name="identifier",
|
||||||
|
field=models.SlugField(max_length=255, unique=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="application",
|
||||||
|
name="meta_icon",
|
||||||
|
field=models.FileField(default=None, null=True, upload_to="application-icons/"),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="application",
|
||||||
|
name="meta_icon",
|
||||||
|
field=models.FileField(
|
||||||
|
default=None, max_length=500, null=True, upload_to="application-icons/"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name="authenticatedsession",
|
||||||
|
options={
|
||||||
|
"verbose_name": "Authenticated Session",
|
||||||
|
"verbose_name_plural": "Authenticated Sessions",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.RunPython(
|
||||||
|
code=create_default_user_token,
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="token",
|
||||||
|
name="intent",
|
||||||
|
field=models.TextField(
|
||||||
|
choices=[
|
||||||
|
("verification", "Intent Verification"),
|
||||||
|
("api", "Intent Api"),
|
||||||
|
("recovery", "Intent Recovery"),
|
||||||
|
("app_password", "Intent App Password"),
|
||||||
|
],
|
||||||
|
default="verification",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
@ -26,7 +26,7 @@ class Migration(migrations.Migration):
|
|||||||
),
|
),
|
||||||
(
|
(
|
||||||
"username_link",
|
"username_link",
|
||||||
"Link to a user with identical username address. Can have security implications when a username is used with another source.",
|
"Link to a user with identical username. Can have security implications when a username is used with another source.",
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"username_deny",
|
"username_deny",
|
||||||
|
@ -32,16 +32,12 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
(
|
(
|
||||||
"expires",
|
"expires",
|
||||||
models.DateTimeField(
|
models.DateTimeField(default=authentik.core.models.default_token_duration),
|
||||||
default=authentik.core.models.default_token_duration
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
("expiring", models.BooleanField(default=True)),
|
("expiring", models.BooleanField(default=True)),
|
||||||
(
|
(
|
||||||
"uuid",
|
"uuid",
|
||||||
models.UUIDField(
|
models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False),
|
||||||
default=uuid.uuid4, primary_key=True, serialize=False
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
("session_key", models.CharField(max_length=40)),
|
("session_key", models.CharField(max_length=40)),
|
||||||
("last_ip", models.TextField()),
|
("last_ip", models.TextField()),
|
||||||
|
@ -13,8 +13,6 @@ class Migration(migrations.Migration):
|
|||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name="application",
|
model_name="application",
|
||||||
name="meta_icon",
|
name="meta_icon",
|
||||||
field=models.FileField(
|
field=models.FileField(default=None, null=True, upload_to="application-icons/"),
|
||||||
default=None, null=True, upload_to="application-icons/"
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
# 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/"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name="authenticatedsession",
|
||||||
|
options={
|
||||||
|
"verbose_name": "Authenticated Session",
|
||||||
|
"verbose_name_plural": "Authenticated Sessions",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
37
authentik/core/migrations/0027_bootstrap_token.py
Normal file
37
authentik/core/migrations/0027_bootstrap_token.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# Generated by Django 3.2.5 on 2021-08-11 19:40
|
||||||
|
from os import environ
|
||||||
|
|
||||||
|
from django.apps.registry import Apps
|
||||||
|
from django.db import migrations
|
||||||
|
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
||||||
|
|
||||||
|
|
||||||
|
def create_default_user_token(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
||||||
|
# We have to use a direct import here, otherwise we get an object manager error
|
||||||
|
from authentik.core.models import Token, TokenIntents, User
|
||||||
|
|
||||||
|
db_alias = schema_editor.connection.alias
|
||||||
|
|
||||||
|
akadmin = User.objects.using(db_alias).filter(username="akadmin")
|
||||||
|
if not akadmin.exists():
|
||||||
|
return
|
||||||
|
if "AK_ADMIN_TOKEN" not in environ:
|
||||||
|
return
|
||||||
|
Token.objects.using(db_alias).create(
|
||||||
|
identifier="authentik-boostrap-token",
|
||||||
|
user=akadmin.first(),
|
||||||
|
intent=TokenIntents.INTENT_API,
|
||||||
|
expiring=False,
|
||||||
|
key=environ["AK_ADMIN_TOKEN"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("authentik_core", "0026_alter_application_meta_icon"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(create_default_user_token),
|
||||||
|
]
|
26
authentik/core/migrations/0028_alter_token_intent.py
Normal file
26
authentik/core/migrations/0028_alter_token_intent.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# Generated by Django 3.2.6 on 2021-08-23 14:35
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("authentik_core", "0027_bootstrap_token"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="token",
|
||||||
|
name="intent",
|
||||||
|
field=models.TextField(
|
||||||
|
choices=[
|
||||||
|
("verification", "Intent Verification"),
|
||||||
|
("api", "Intent Api"),
|
||||||
|
("recovery", "Intent Recovery"),
|
||||||
|
("app_password", "Intent App Password"),
|
||||||
|
],
|
||||||
|
default="verification",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
@ -28,6 +28,7 @@ from authentik.core.signals import password_changed
|
|||||||
from authentik.core.types import UILoginButton, UserSettingSerializer
|
from authentik.core.types import UILoginButton, UserSettingSerializer
|
||||||
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.generators import generate_id
|
||||||
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.lib.utils.http import get_client_ip
|
||||||
from authentik.managed.models import ManagedModel
|
from authentik.managed.models import ManagedModel
|
||||||
@ -37,6 +38,10 @@ 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_CHANGE_USERNAME = "goauthentik.io/user/can-change-username"
|
||||||
|
USER_ATTRIBUTE_CHANGE_EMAIL = "goauthentik.io/user/can-change-email"
|
||||||
|
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")
|
||||||
@ -52,7 +57,9 @@ def default_token_duration():
|
|||||||
|
|
||||||
def default_token_key():
|
def default_token_key():
|
||||||
"""Default token key"""
|
"""Default token key"""
|
||||||
return uuid4().hex
|
# We use generate_id since the chars in the key should be easy
|
||||||
|
# to use in Emails (for verification) and URLs (for recovery)
|
||||||
|
return generate_id(128)
|
||||||
|
|
||||||
|
|
||||||
class Group(models.Model):
|
class Group(models.Model):
|
||||||
@ -152,9 +159,7 @@ class User(GuardianUserMixin, AbstractUser):
|
|||||||
("s", "158"),
|
("s", "158"),
|
||||||
("r", "g"),
|
("r", "g"),
|
||||||
]
|
]
|
||||||
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)
|
||||||
return mode % {
|
return mode % {
|
||||||
"username": self.username,
|
"username": self.username,
|
||||||
@ -184,9 +189,7 @@ class Provider(SerializerModel):
|
|||||||
related_name="provider_authorization",
|
related_name="provider_authorization",
|
||||||
)
|
)
|
||||||
|
|
||||||
property_mappings = models.ManyToManyField(
|
property_mappings = models.ManyToManyField("PropertyMapping", default=None, blank=True)
|
||||||
"PropertyMapping", default=None, blank=True
|
|
||||||
)
|
|
||||||
|
|
||||||
objects = InheritanceManager()
|
objects = InheritanceManager()
|
||||||
|
|
||||||
@ -216,9 +219,7 @@ 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(
|
slug = models.SlugField(help_text=_("Internal application name, used in URLs."), unique=True)
|
||||||
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
|
||||||
)
|
)
|
||||||
@ -228,7 +229,10 @@ class Application(PolicyBindingModel):
|
|||||||
)
|
)
|
||||||
# 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(
|
meta_icon = models.FileField(
|
||||||
upload_to="application-icons/", default=None, null=True
|
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)
|
||||||
@ -239,9 +243,7 @@ class Application(PolicyBindingModel):
|
|||||||
it is returned as-is"""
|
it is returned as-is"""
|
||||||
if not self.meta_icon:
|
if not self.meta_icon:
|
||||||
return None
|
return None
|
||||||
if self.meta_icon.name.startswith("http") or self.meta_icon.name.startswith(
|
if self.meta_icon.name.startswith("http") or self.meta_icon.name.startswith("/static"):
|
||||||
"/static"
|
|
||||||
):
|
|
||||||
return self.meta_icon.name
|
return self.meta_icon.name
|
||||||
return self.meta_icon.url
|
return self.meta_icon.url
|
||||||
|
|
||||||
@ -283,7 +285,7 @@ class SourceUserMatchingModes(models.TextChoices):
|
|||||||
)
|
)
|
||||||
USERNAME_LINK = "username_link", _(
|
USERNAME_LINK = "username_link", _(
|
||||||
(
|
(
|
||||||
"Link to a user with identical username address. Can have security implications "
|
"Link to a user with identical username. Can have security implications "
|
||||||
"when a username is used with another source."
|
"when a username is used with another source."
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -296,14 +298,10 @@ class Source(ManagedModel, SerializerModel, PolicyBindingModel):
|
|||||||
"""Base Authentication source, i.e. an OAuth Provider, SAML Remote or LDAP Server"""
|
"""Base Authentication source, i.e. an OAuth Provider, SAML Remote or LDAP Server"""
|
||||||
|
|
||||||
name = models.TextField(help_text=_("Source's display Name."))
|
name = models.TextField(help_text=_("Source's display Name."))
|
||||||
slug = models.SlugField(
|
slug = models.SlugField(help_text=_("Internal source name, used in URLs."), unique=True)
|
||||||
help_text=_("Internal source name, used in URLs."), unique=True
|
|
||||||
)
|
|
||||||
|
|
||||||
enabled = models.BooleanField(default=True)
|
enabled = models.BooleanField(default=True)
|
||||||
property_mappings = models.ManyToManyField(
|
property_mappings = models.ManyToManyField("PropertyMapping", default=None, blank=True)
|
||||||
"PropertyMapping", default=None, blank=True
|
|
||||||
)
|
|
||||||
|
|
||||||
authentication_flow = models.ForeignKey(
|
authentication_flow = models.ForeignKey(
|
||||||
Flow,
|
Flow,
|
||||||
@ -377,6 +375,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,
|
||||||
@ -408,6 +413,9 @@ class TokenIntents(models.TextChoices):
|
|||||||
# Recovery use for the recovery app
|
# Recovery use for the recovery app
|
||||||
INTENT_RECOVERY = "recovery"
|
INTENT_RECOVERY = "recovery"
|
||||||
|
|
||||||
|
# App-specific passwords
|
||||||
|
INTENT_APP_PASSWORD = "app_password" # nosec
|
||||||
|
|
||||||
|
|
||||||
class Token(ManagedModel, ExpiringModel):
|
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."""
|
||||||
@ -421,6 +429,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:
|
||||||
@ -457,9 +478,7 @@ class PropertyMapping(SerializerModel, ManagedModel):
|
|||||||
"""Get serializer for this model"""
|
"""Get serializer for this model"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def evaluate(
|
def evaluate(self, user: Optional[User], request: Optional[HttpRequest], **kwargs) -> Any:
|
||||||
self, user: Optional[User], request: Optional[HttpRequest], **kwargs
|
|
||||||
) -> Any:
|
|
||||||
"""Evaluate `self.expression` using `**kwargs` as Context."""
|
"""Evaluate `self.expression` using `**kwargs` as Context."""
|
||||||
from authentik.core.expression import PropertyMappingEvaluator
|
from authentik.core.expression import PropertyMappingEvaluator
|
||||||
|
|
||||||
@ -467,8 +486,8 @@ class PropertyMapping(SerializerModel, ManagedModel):
|
|||||||
evaluator.set_context(user, request, self, **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}"
|
||||||
@ -498,9 +517,7 @@ class AuthenticatedSession(ExpiringModel):
|
|||||||
last_used = models.DateTimeField(auto_now=True)
|
last_used = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_request(
|
def from_request(request: HttpRequest, user: User) -> Optional["AuthenticatedSession"]:
|
||||||
request: HttpRequest, user: User
|
|
||||||
) -> Optional["AuthenticatedSession"]:
|
|
||||||
"""Create a new session from a http request"""
|
"""Create a new session from a http request"""
|
||||||
if not hasattr(request, "session") or not request.session.session_key:
|
if not hasattr(request, "session") or not request.session.session_key:
|
||||||
return None
|
return None
|
||||||
@ -511,3 +528,8 @@ class AuthenticatedSession(ExpiringModel):
|
|||||||
last_user_agent=request.META.get("HTTP_USER_AGENT", ""),
|
last_user_agent=request.META.get("HTTP_USER_AGENT", ""),
|
||||||
expires=request.session.get_expiry_date(),
|
expires=request.session.get_expiry_date(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
|
||||||
|
verbose_name = _("Authenticated Session")
|
||||||
|
verbose_name_plural = _("Authenticated Sessions")
|
||||||
|
@ -14,9 +14,7 @@ from prometheus_client import Gauge
|
|||||||
# Arguments: user: User, password: str
|
# Arguments: user: User, password: str
|
||||||
password_changed = Signal()
|
password_changed = Signal()
|
||||||
|
|
||||||
GAUGE_MODELS = Gauge(
|
GAUGE_MODELS = Gauge("authentik_models", "Count of various objects", ["model_name", "app"])
|
||||||
"authentik_models", "Count of various objects", ["model_name", "app"]
|
|
||||||
)
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from authentik.core.models import AuthenticatedSession, User
|
from authentik.core.models import AuthenticatedSession, User
|
||||||
@ -60,15 +58,11 @@ def user_logged_out_session(sender, request: HttpRequest, user: "User", **_):
|
|||||||
"""Delete AuthenticatedSession if it exists"""
|
"""Delete AuthenticatedSession if it exists"""
|
||||||
from authentik.core.models import AuthenticatedSession
|
from authentik.core.models import AuthenticatedSession
|
||||||
|
|
||||||
AuthenticatedSession.objects.filter(
|
AuthenticatedSession.objects.filter(session_key=request.session.session_key).delete()
|
||||||
session_key=request.session.session_key
|
|
||||||
).delete()
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(pre_delete)
|
@receiver(pre_delete)
|
||||||
def authenticated_session_delete(
|
def authenticated_session_delete(sender: Type[Model], instance: "AuthenticatedSession", **_):
|
||||||
sender: Type[Model], instance: "AuthenticatedSession", **_
|
|
||||||
):
|
|
||||||
"""Delete session when authenticated session is deleted"""
|
"""Delete session when authenticated session is deleted"""
|
||||||
from authentik.core.models import AuthenticatedSession
|
from authentik.core.models import AuthenticatedSession
|
||||||
|
|
||||||
|
@ -11,16 +11,8 @@ from django.urls import reverse
|
|||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
from structlog.stdlib import get_logger
|
from structlog.stdlib import get_logger
|
||||||
|
|
||||||
from authentik.core.models import (
|
from authentik.core.models import Source, SourceUserMatchingModes, User, UserSourceConnection
|
||||||
Source,
|
from authentik.core.sources.stage import PLAN_CONTEXT_SOURCES_CONNECTION, PostUserEnrollmentStage
|
||||||
SourceUserMatchingModes,
|
|
||||||
User,
|
|
||||||
UserSourceConnection,
|
|
||||||
)
|
|
||||||
from authentik.core.sources.stage import (
|
|
||||||
PLAN_CONTEXT_SOURCES_CONNECTION,
|
|
||||||
PostUserEnrollmentStage,
|
|
||||||
)
|
|
||||||
from authentik.events.models import Event, EventAction
|
from authentik.events.models import Event, EventAction
|
||||||
from authentik.flows.models import Flow, Stage, in_memory_stage
|
from authentik.flows.models import Flow, Stage, in_memory_stage
|
||||||
from authentik.flows.planner import (
|
from authentik.flows.planner import (
|
||||||
@ -30,10 +22,10 @@ from authentik.flows.planner import (
|
|||||||
PLAN_CONTEXT_SSO,
|
PLAN_CONTEXT_SSO,
|
||||||
FlowPlanner,
|
FlowPlanner,
|
||||||
)
|
)
|
||||||
from authentik.flows.views import NEXT_ARG_NAME, SESSION_KEY_GET, SESSION_KEY_PLAN
|
from authentik.flows.views.executor import NEXT_ARG_NAME, SESSION_KEY_GET, SESSION_KEY_PLAN
|
||||||
from authentik.lib.utils.urls import redirect_with_qs
|
from authentik.lib.utils.urls import redirect_with_qs
|
||||||
from authentik.policies.utils import delete_none_keys
|
from authentik.policies.utils import delete_none_keys
|
||||||
from authentik.stages.password import BACKEND_DJANGO
|
from authentik.stages.password import BACKEND_INBUILT
|
||||||
from authentik.stages.password.stage import PLAN_CONTEXT_AUTHENTICATION_BACKEND
|
from authentik.stages.password.stage import PLAN_CONTEXT_AUTHENTICATION_BACKEND
|
||||||
from authentik.stages.prompt.stage import PLAN_CONTEXT_PROMPT
|
from authentik.stages.prompt.stage import PLAN_CONTEXT_PROMPT
|
||||||
|
|
||||||
@ -76,9 +68,7 @@ class SourceFlowManager:
|
|||||||
# pylint: disable=too-many-return-statements
|
# pylint: disable=too-many-return-statements
|
||||||
def get_action(self, **kwargs) -> tuple[Action, Optional[UserSourceConnection]]:
|
def get_action(self, **kwargs) -> tuple[Action, Optional[UserSourceConnection]]:
|
||||||
"""decide which action should be taken"""
|
"""decide which action should be taken"""
|
||||||
new_connection = self.connection_type(
|
new_connection = self.connection_type(source=self.source, identifier=self.identifier)
|
||||||
source=self.source, identifier=self.identifier
|
|
||||||
)
|
|
||||||
# When request is authenticated, always link
|
# When request is authenticated, always link
|
||||||
if self.request.user.is_authenticated:
|
if self.request.user.is_authenticated:
|
||||||
new_connection.user = self.request.user
|
new_connection.user = self.request.user
|
||||||
@ -113,9 +103,7 @@ class SourceFlowManager:
|
|||||||
SourceUserMatchingModes.USERNAME_DENY,
|
SourceUserMatchingModes.USERNAME_DENY,
|
||||||
]:
|
]:
|
||||||
if not self.enroll_info.get("username", None):
|
if not self.enroll_info.get("username", None):
|
||||||
self._logger.warning(
|
self._logger.warning("Refusing to use none username", source=self.source)
|
||||||
"Refusing to use none username", source=self.source
|
|
||||||
)
|
|
||||||
return Action.DENY, None
|
return Action.DENY, None
|
||||||
query = Q(username__exact=self.enroll_info.get("username", None))
|
query = Q(username__exact=self.enroll_info.get("username", None))
|
||||||
self._logger.debug("trying to link with existing user", query=query)
|
self._logger.debug("trying to link with existing user", query=query)
|
||||||
@ -141,11 +129,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
|
||||||
|
|
||||||
@ -178,7 +166,7 @@ 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]:
|
||||||
@ -196,12 +184,12 @@ class SourceFlowManager:
|
|||||||
# Ensure redirect is carried through when user was trying to
|
# Ensure redirect is carried through when user was trying to
|
||||||
# authorize application
|
# authorize application
|
||||||
final_redirect = self.request.session.get(SESSION_KEY_GET, {}).get(
|
final_redirect = self.request.session.get(SESSION_KEY_GET, {}).get(
|
||||||
NEXT_ARG_NAME, "authentik_core:if-admin"
|
NEXT_ARG_NAME, "authentik_core:if-user"
|
||||||
)
|
)
|
||||||
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: BACKEND_DJANGO,
|
PLAN_CONTEXT_AUTHENTICATION_BACKEND: BACKEND_INBUILT,
|
||||||
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,
|
||||||
@ -229,10 +217,7 @@ class SourceFlowManager:
|
|||||||
"""Login user and redirect."""
|
"""Login user and redirect."""
|
||||||
messages.success(
|
messages.success(
|
||||||
self.request,
|
self.request,
|
||||||
_(
|
_("Successfully authenticated with %(source)s!" % {"source": self.source.name}),
|
||||||
"Successfully authenticated with %(source)s!"
|
|
||||||
% {"source": self.source.name}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
flow_kwargs = {PLAN_CONTEXT_PENDING_USER: connection.user}
|
flow_kwargs = {PLAN_CONTEXT_PENDING_USER: connection.user}
|
||||||
return self._handle_login_flow(self.source.authentication_flow, **flow_kwargs)
|
return self._handle_login_flow(self.source.authentication_flow, **flow_kwargs)
|
||||||
@ -258,9 +243,9 @@ class SourceFlowManager:
|
|||||||
return self.handle_auth_user(connection)
|
return self.handle_auth_user(connection)
|
||||||
return redirect(
|
return redirect(
|
||||||
reverse(
|
reverse(
|
||||||
"authentik_core:if-admin",
|
"authentik_core:if-user",
|
||||||
)
|
)
|
||||||
+ f"#/user;page-{self.source.slug}"
|
+ f"#/settings;page-{self.source.slug}"
|
||||||
)
|
)
|
||||||
|
|
||||||
def handle_enroll(
|
def handle_enroll(
|
||||||
@ -270,10 +255,7 @@ class SourceFlowManager:
|
|||||||
"""User was not authenticated and previous request was not authenticated."""
|
"""User was not authenticated and previous request was not authenticated."""
|
||||||
messages.success(
|
messages.success(
|
||||||
self.request,
|
self.request,
|
||||||
_(
|
_("Successfully authenticated with %(source)s!" % {"source": self.source.name}),
|
||||||
"Successfully authenticated with %(source)s!"
|
|
||||||
% {"source": self.source.name}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# We run the Flow planner here so we can pass the Pending user in the context
|
# We run the Flow planner here so we can pass the Pending user in the context
|
||||||
|
@ -28,3 +28,7 @@ class PostUserEnrollmentStage(StageView):
|
|||||||
source=connection.source,
|
source=connection.source,
|
||||||
).from_http(self.request)
|
).from_http(self.request)
|
||||||
return self.executor.stage_ok()
|
return self.executor.stage_ok()
|
||||||
|
|
||||||
|
def post(self, request: HttpRequest) -> HttpResponse:
|
||||||
|
"""Wrapper for post requests"""
|
||||||
|
return self.get(request)
|
||||||
|
@ -6,14 +6,22 @@ from os import environ
|
|||||||
from boto3.exceptions import Boto3Error
|
from boto3.exceptions import Boto3Error
|
||||||
from botocore.exceptions import BotoCoreError, ClientError
|
from botocore.exceptions import BotoCoreError, ClientError
|
||||||
from dbbackup.db.exceptions import CommandConnectorError
|
from dbbackup.db.exceptions import CommandConnectorError
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib.humanize.templatetags.humanize import naturaltime
|
from django.contrib.humanize.templatetags.humanize import naturaltime
|
||||||
|
from django.contrib.sessions.backends.cache import KEY_PREFIX
|
||||||
from django.core import management
|
from django.core import management
|
||||||
|
from django.core.cache import cache
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
from kubernetes.config.incluster_config import SERVICE_HOST_ENV_NAME
|
from kubernetes.config.incluster_config import SERVICE_HOST_ENV_NAME
|
||||||
from structlog.stdlib import get_logger
|
from structlog.stdlib import get_logger
|
||||||
|
|
||||||
from authentik.core.models import ExpiringModel
|
from authentik.core.models import AuthenticatedSession, ExpiringModel
|
||||||
from authentik.events.monitored_tasks import MonitoredTask, TaskResult, TaskResultStatus
|
from authentik.events.monitored_tasks import (
|
||||||
|
MonitoredTask,
|
||||||
|
TaskResult,
|
||||||
|
TaskResultStatus,
|
||||||
|
prefill_task,
|
||||||
|
)
|
||||||
from authentik.lib.config import CONFIG
|
from authentik.lib.config import CONFIG
|
||||||
from authentik.root.celery import CELERY_APP
|
from authentik.root.celery import CELERY_APP
|
||||||
|
|
||||||
@ -21,39 +29,52 @@ LOGGER = get_logger()
|
|||||||
|
|
||||||
|
|
||||||
@CELERY_APP.task(bind=True, base=MonitoredTask)
|
@CELERY_APP.task(bind=True, base=MonitoredTask)
|
||||||
|
@prefill_task()
|
||||||
def clean_expired_models(self: MonitoredTask):
|
def clean_expired_models(self: MonitoredTask):
|
||||||
"""Remove expired objects"""
|
"""Remove expired objects"""
|
||||||
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=True, expires__gt=now())
|
||||||
.exclude(expiring=False)
|
|
||||||
.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}")
|
||||||
|
# Special case
|
||||||
|
amount = 0
|
||||||
|
for session in AuthenticatedSession.objects.all():
|
||||||
|
cache_key = f"{KEY_PREFIX}{session.session_key}"
|
||||||
|
value = cache.get(cache_key)
|
||||||
|
if not value:
|
||||||
|
session.delete()
|
||||||
|
amount += 1
|
||||||
|
LOGGER.debug("Expired sessions", model=AuthenticatedSession, amount=amount)
|
||||||
|
messages.append(f"Expired {amount} {AuthenticatedSession._meta.verbose_name_plural}")
|
||||||
self.set_status(TaskResult(TaskResultStatus.SUCCESSFUL, messages))
|
self.set_status(TaskResult(TaskResultStatus.SUCCESSFUL, messages))
|
||||||
|
|
||||||
|
|
||||||
|
def should_backup() -> bool:
|
||||||
|
"""Check if we should be doing backups"""
|
||||||
|
if SERVICE_HOST_ENV_NAME in environ and not CONFIG.y("postgresql.s3_backup.bucket"):
|
||||||
|
LOGGER.info("Running in k8s and s3 backups are not configured, skipping")
|
||||||
|
return False
|
||||||
|
if not CONFIG.y_bool("postgresql.backup.enabled"):
|
||||||
|
return False
|
||||||
|
if settings.DEBUG:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
@CELERY_APP.task(bind=True, base=MonitoredTask)
|
@CELERY_APP.task(bind=True, base=MonitoredTask)
|
||||||
|
@prefill_task()
|
||||||
def backup_database(self: MonitoredTask): # pragma: no cover
|
def backup_database(self: MonitoredTask): # pragma: no cover
|
||||||
"""Database backup"""
|
"""Database backup"""
|
||||||
self.result_timeout_hours = 25
|
self.result_timeout_hours = 25
|
||||||
if SERVICE_HOST_ENV_NAME in environ and not CONFIG.y("postgresql.s3_backup"):
|
if not should_backup():
|
||||||
LOGGER.info("Running in k8s and s3 backups are not configured, skipping")
|
self.set_status(TaskResult(TaskResultStatus.UNKNOWN, ["Backups are not configured."]))
|
||||||
self.set_status(
|
|
||||||
TaskResult(
|
|
||||||
TaskResultStatus.WARNING,
|
|
||||||
[
|
|
||||||
(
|
|
||||||
"Skipping backup as authentik is running in Kubernetes "
|
|
||||||
"without S3 backups configured."
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
start = datetime.now()
|
start = datetime.now()
|
||||||
|
@ -8,16 +8,15 @@
|
|||||||
<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:tenant.branding_title %}{% endblock %}</title>
|
<title>{% block title %}{% trans title|default:tenant.branding_title %}{% endblock %}</title>
|
||||||
<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' %}">
|
||||||
<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' %}">
|
||||||
<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' %}">
|
||||||
<link rel="stylesheet" type="text/css" href="{% static 'dist/empty-state.css' %}?v={{ ak_version }}">
|
<link rel="stylesheet" type="text/css" href="{% static 'dist/empty-state.css' %}">
|
||||||
<link rel="stylesheet" type="text/css" href="{% static 'dist/spinner.css' %}?v={{ ak_version }}">
|
<link rel="stylesheet" type="text/css" href="{% static 'dist/spinner.css' %}">
|
||||||
{% block head_before %}
|
{% block head_before %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
<link rel="stylesheet" type="text/css" href="{% static 'dist/authentik.css' %}?v={{ ak_version }}">
|
<link rel="stylesheet" type="text/css" href="{% static 'dist/authentik.css' %}">
|
||||||
<script src="{% static 'dist/poly.js' %}?v={{ ak_version }}" type="module"></script>
|
<script src="{% static 'dist/poly.js' %}" type="module"></script>
|
||||||
<script>window["polymerSkipLoadingFontRoboto"] = true;</script>
|
|
||||||
{% block head %}
|
{% block head %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block head %}
|
{% block head %}
|
||||||
<script src="{% static 'dist/AdminInterface.js' %}?v={{ ak_version }}" type="module"></script>
|
<script src="{% static 'dist/AdminInterface.js' %}" type="module"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
@ -21,7 +21,7 @@ You've logged out of {{ application }}.
|
|||||||
{% endblocktrans %}
|
{% endblocktrans %}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<a id="ak-back-home" href="{% url 'authentik_core:if-admin' %}" class="pf-c-button pf-m-primary">{% trans 'Go back to overview' %}</a>
|
<a id="ak-back-home" href="{% url 'authentik_core:root-redirect' %}" class="pf-c-button pf-m-primary">{% trans 'Go back to overview' %}</a>
|
||||||
|
|
||||||
<a id="logout" href="{% url 'authentik_flows:default-invalidation' %}" class="pf-c-button pf-m-secondary">{% trans 'Log out of authentik' %}</a>
|
<a id="logout" href="{% url 'authentik_flows:default-invalidation' %}" class="pf-c-button pf-m-secondary">{% trans 'Log out of authentik' %}</a>
|
||||||
|
|
||||||
|
@ -4,13 +4,14 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block head_before %}
|
{% block head_before %}
|
||||||
{% if flow.compatibility_mode %}
|
{{ block.super }}
|
||||||
|
{% if flow.compatibility_mode and not inspector %}
|
||||||
<script>ShadyDOM = { force: !navigator.webdriver };</script>
|
<script>ShadyDOM = { force: !navigator.webdriver };</script>
|
||||||
{% endif %}
|
{% 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' %}" type="module"></script>
|
||||||
<style>
|
<style>
|
||||||
.pf-c-background-image::before {
|
.pf-c-background-image::before {
|
||||||
--ak-flow-background: url("{{ flow.background_url }}");
|
--ak-flow-background: url("{{ flow.background_url }}");
|
||||||
|
28
authentik/core/templates/if/user.html
Normal file
28
authentik/core/templates/if/user.html
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
{% extends "base/skeleton.html" %}
|
||||||
|
|
||||||
|
{% load static %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block head %}
|
||||||
|
<script src="{% static 'dist/UserInterface.js' %}" type="module"></script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<ak-message-container></ak-message-container>
|
||||||
|
<ak-interface-user>
|
||||||
|
<section class="ak-static-page pf-c-page__main-section pf-m-no-padding-mobile pf-m-xl">
|
||||||
|
<div class="pf-c-empty-state" style="height: 100vh;">
|
||||||
|
<div class="pf-c-empty-state__content">
|
||||||
|
<span class="pf-c-spinner pf-m-xl pf-c-empty-state__icon" role="progressbar" aria-valuetext="{% trans 'Loading...' %}">
|
||||||
|
<span class="pf-c-spinner__clipper"></span>
|
||||||
|
<span class="pf-c-spinner__lead-ball"></span>
|
||||||
|
<span class="pf-c-spinner__tail-ball"></span>
|
||||||
|
</span>
|
||||||
|
<h1 class="pf-c-title pf-m-lg">
|
||||||
|
{% trans "Loading..." %}
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</ak-interface-user>
|
||||||
|
{% endblock %}
|
@ -4,7 +4,7 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block head_before %}
|
{% block head_before %}
|
||||||
<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' %}">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block head %}
|
{% block head %}
|
||||||
@ -61,7 +61,7 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if tenant.branding_title != "authentik" %}
|
{% if tenant.branding_title != "authentik" %}
|
||||||
<li>
|
<li>
|
||||||
<a href="https://goauthentik.io">
|
<a href="https://goauthentik.io?utm_source=authentik">
|
||||||
{% trans 'Powered by authentik' %}
|
{% trans 'Powered by authentik' %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
@ -17,9 +17,7 @@ class TestApplicationsAPI(APITestCase):
|
|||||||
self.denied = Application.objects.create(name="denied", slug="denied")
|
self.denied = Application.objects.create(name="denied", slug="denied")
|
||||||
PolicyBinding.objects.create(
|
PolicyBinding.objects.create(
|
||||||
target=self.denied,
|
target=self.denied,
|
||||||
policy=DummyPolicy.objects.create(
|
policy=DummyPolicy.objects.create(name="deny", result=False, wait_min=1, wait_max=2),
|
||||||
name="deny", result=False, wait_min=1, wait_max=2
|
|
||||||
),
|
|
||||||
order=0,
|
order=0,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -33,9 +31,7 @@ class TestApplicationsAPI(APITestCase):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertJSONEqual(
|
self.assertJSONEqual(force_str(response.content), {"messages": [], "passing": True})
|
||||||
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",
|
||||||
@ -43,9 +39,7 @@ class TestApplicationsAPI(APITestCase):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertJSONEqual(
|
self.assertJSONEqual(force_str(response.content), {"messages": ["dummy"], "passing": False})
|
||||||
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"""
|
||||||
|
@ -46,9 +46,7 @@ class TestImpersonation(TestCase):
|
|||||||
self.client.force_login(self.other_user)
|
self.client.force_login(self.other_user)
|
||||||
|
|
||||||
self.client.get(
|
self.client.get(
|
||||||
reverse(
|
reverse("authentik_core:impersonate-init", kwargs={"user_id": self.akadmin.pk})
|
||||||
"authentik_core:impersonate-init", kwargs={"user_id": self.akadmin.pk}
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
response = self.client.get(reverse("authentik_api:user-me"))
|
response = self.client.get(reverse("authentik_api:user-me"))
|
||||||
@ -60,4 +58,4 @@ class TestImpersonation(TestCase):
|
|||||||
self.client.force_login(self.other_user)
|
self.client.force_login(self.other_user)
|
||||||
|
|
||||||
response = self.client.get(reverse("authentik_core:impersonate-end"))
|
response = self.client.get(reverse("authentik_core:impersonate-end"))
|
||||||
self.assertRedirects(response, reverse("authentik_core:if-admin"))
|
self.assertRedirects(response, reverse("authentik_core:if-user"))
|
||||||
|
@ -22,9 +22,7 @@ class TestModels(TestCase):
|
|||||||
|
|
||||||
def test_token_expire_no_expire(self):
|
def test_token_expire_no_expire(self):
|
||||||
"""Test token expiring with "expiring" set"""
|
"""Test token expiring with "expiring" set"""
|
||||||
token = Token.objects.create(
|
token = Token.objects.create(expires=now(), user=get_anonymous_user(), expiring=False)
|
||||||
expires=now(), user=get_anonymous_user(), expiring=False
|
|
||||||
)
|
|
||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
self.assertFalse(token.is_expired)
|
self.assertFalse(token.is_expired)
|
||||||
|
|
||||||
|
@ -16,9 +16,7 @@ class TestPropertyMappings(TestCase):
|
|||||||
|
|
||||||
def test_expression(self):
|
def test_expression(self):
|
||||||
"""Test expression"""
|
"""Test expression"""
|
||||||
mapping = PropertyMapping.objects.create(
|
mapping = PropertyMapping.objects.create(name="test", expression="return 'test'")
|
||||||
name="test", expression="return 'test'"
|
|
||||||
)
|
|
||||||
self.assertEqual(mapping.evaluate(None, None), "test")
|
self.assertEqual(mapping.evaluate(None, None), "test")
|
||||||
|
|
||||||
def test_expression_syntax(self):
|
def test_expression_syntax(self):
|
||||||
@ -31,7 +29,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 +42,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
|
||||||
|
@ -23,9 +23,7 @@ class TestPropertyMappingAPI(APITestCase):
|
|||||||
def test_test_call(self):
|
def test_test_call(self):
|
||||||
"""Test PropertMappings's test endpoint"""
|
"""Test PropertMappings's test endpoint"""
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
reverse(
|
reverse("authentik_api:propertymapping-test", kwargs={"pk": self.mapping.pk}),
|
||||||
"authentik_api:propertymapping-test", kwargs={"pk": self.mapping.pk}
|
|
||||||
),
|
|
||||||
data={
|
data={
|
||||||
"user": self.user.pk,
|
"user": self.user.pk,
|
||||||
},
|
},
|
||||||
|
145
authentik/core/tests/test_source_flow_manager.py
Normal file
145
authentik/core/tests/test_source_flow_manager.py
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
"""Test Source flow_manager"""
|
||||||
|
from django.contrib.auth.models import AnonymousUser
|
||||||
|
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.lib.generators import generate_id
|
||||||
|
from authentik.lib.tests.utils import get_request
|
||||||
|
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_id()
|
||||||
|
|
||||||
|
def test_unauthenticated_enroll(self):
|
||||||
|
"""Test un-authenticated user enrolling"""
|
||||||
|
flow_manager = OAuthSourceFlowManager(
|
||||||
|
self.source, get_request("/", user=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, get_request("/", user=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, get_request("/", user=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, get_request("/", user=AnonymousUser()), self.identifier, {}
|
||||||
|
)
|
||||||
|
action, _ = flow_manager.get_action()
|
||||||
|
self.assertEqual(action, Action.DENY)
|
||||||
|
flow_manager.get_flow()
|
||||||
|
# With email
|
||||||
|
flow_manager = OAuthSourceFlowManager(
|
||||||
|
self.source,
|
||||||
|
get_request("/", user=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, get_request("/", user=AnonymousUser()), self.identifier, {}
|
||||||
|
)
|
||||||
|
action, _ = flow_manager.get_action()
|
||||||
|
self.assertEqual(action, Action.DENY)
|
||||||
|
flow_manager.get_flow()
|
||||||
|
# With username
|
||||||
|
flow_manager = OAuthSourceFlowManager(
|
||||||
|
self.source,
|
||||||
|
get_request("/", user=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,
|
||||||
|
get_request("/", user=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,
|
||||||
|
get_request("/", user=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,
|
||||||
|
get_request("/", user=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,13 @@
|
|||||||
"""Test token API"""
|
"""Test token API"""
|
||||||
|
from json import loads
|
||||||
|
|
||||||
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):
|
||||||
@ -10,7 +15,8 @@ class TestTokenAPI(APITestCase):
|
|||||||
|
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.user = User.objects.get(username="akadmin")
|
self.user = User.objects.create(username="testuser")
|
||||||
|
self.admin = User.objects.get(username="akadmin")
|
||||||
self.client.force_login(self.user)
|
self.client.force_login(self.user)
|
||||||
|
|
||||||
def test_token_create(self):
|
def test_token_create(self):
|
||||||
@ -22,3 +28,59 @@ 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_invalid(self):
|
||||||
|
"""Test token creation endpoint (invalid data)"""
|
||||||
|
response = self.client.post(
|
||||||
|
reverse("authentik_api:token-list"),
|
||||||
|
{"identifier": "test-token", "intent": TokenIntents.INTENT_RECOVERY},
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 400)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
def test_list(self):
|
||||||
|
"""Test Token List (Test normal authentication)"""
|
||||||
|
token_should: Token = Token.objects.create(
|
||||||
|
identifier="test", expiring=False, user=self.user
|
||||||
|
)
|
||||||
|
Token.objects.create(identifier="test-2", expiring=False, user=get_anonymous_user())
|
||||||
|
response = self.client.get(reverse(("authentik_api:token-list")))
|
||||||
|
body = loads(response.content)
|
||||||
|
self.assertEqual(len(body["results"]), 1)
|
||||||
|
self.assertEqual(body["results"][0]["identifier"], token_should.identifier)
|
||||||
|
|
||||||
|
def test_list_admin(self):
|
||||||
|
"""Test Token List (Test with admin auth)"""
|
||||||
|
self.client.force_login(self.admin)
|
||||||
|
token_should: Token = Token.objects.create(
|
||||||
|
identifier="test", expiring=False, user=self.user
|
||||||
|
)
|
||||||
|
token_should_not: Token = Token.objects.create(
|
||||||
|
identifier="test-2", expiring=False, user=get_anonymous_user()
|
||||||
|
)
|
||||||
|
response = self.client.get(reverse(("authentik_api:token-list")))
|
||||||
|
body = loads(response.content)
|
||||||
|
self.assertEqual(len(body["results"]), 2)
|
||||||
|
self.assertEqual(body["results"][0]["identifier"], token_should.identifier)
|
||||||
|
self.assertEqual(body["results"][1]["identifier"], token_should_not.identifier)
|
||||||
|
40
authentik/core/tests/test_token_auth.py
Normal file
40
authentik/core/tests/test_token_auth.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
"""Test token auth"""
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from authentik.core.auth import TokenBackend
|
||||||
|
from authentik.core.models import Token, TokenIntents, User
|
||||||
|
from authentik.flows.planner import FlowPlan
|
||||||
|
from authentik.flows.views.executor import SESSION_KEY_PLAN
|
||||||
|
from authentik.lib.tests.utils import get_request
|
||||||
|
|
||||||
|
|
||||||
|
class TestTokenAuth(TestCase):
|
||||||
|
"""Test token auth"""
|
||||||
|
|
||||||
|
def setUp(self) -> None:
|
||||||
|
self.user = User.objects.create(username="test-user")
|
||||||
|
self.token = Token.objects.create(
|
||||||
|
expiring=False, user=self.user, intent=TokenIntents.INTENT_APP_PASSWORD
|
||||||
|
)
|
||||||
|
# To test with session we need to create a request and pass it through all middlewares
|
||||||
|
self.request = get_request("/")
|
||||||
|
self.request.session[SESSION_KEY_PLAN] = FlowPlan("test")
|
||||||
|
|
||||||
|
def test_token_auth(self):
|
||||||
|
"""Test auth with token"""
|
||||||
|
self.assertEqual(
|
||||||
|
TokenBackend().authenticate(self.request, "test-user", self.token.key), self.user
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_token_auth_none(self):
|
||||||
|
"""Test auth with token (non-existent user)"""
|
||||||
|
self.assertIsNone(
|
||||||
|
TokenBackend().authenticate(self.request, "test-user-foo", self.token.key), self.user
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_token_auth_invalid(self):
|
||||||
|
"""Test auth with token (invalid token)"""
|
||||||
|
self.assertIsNone(
|
||||||
|
TokenBackend().authenticate(self.request, "test-user", self.token.key + "foo"),
|
||||||
|
self.user,
|
||||||
|
)
|
@ -2,7 +2,10 @@
|
|||||||
from django.urls.base import reverse
|
from django.urls.base import reverse
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
|
|
||||||
from authentik.core.models import User
|
from authentik.core.models import USER_ATTRIBUTE_CHANGE_EMAIL, USER_ATTRIBUTE_CHANGE_USERNAME, User
|
||||||
|
from authentik.flows.models import Flow, FlowDesignation
|
||||||
|
from authentik.stages.email.models import EmailStage
|
||||||
|
from authentik.tenants.models import Tenant
|
||||||
|
|
||||||
|
|
||||||
class TestUsersAPI(APITestCase):
|
class TestUsersAPI(APITestCase):
|
||||||
@ -12,6 +15,34 @@ class TestUsersAPI(APITestCase):
|
|||||||
self.admin = User.objects.get(username="akadmin")
|
self.admin = User.objects.get(username="akadmin")
|
||||||
self.user = User.objects.create(username="test-user")
|
self.user = User.objects.create(username="test-user")
|
||||||
|
|
||||||
|
def test_update_self(self):
|
||||||
|
"""Test update_self"""
|
||||||
|
self.client.force_login(self.admin)
|
||||||
|
response = self.client.put(
|
||||||
|
reverse("authentik_api:user-update-self"), data={"username": "foo", "name": "foo"}
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_update_self_username_denied(self):
|
||||||
|
"""Test update_self"""
|
||||||
|
self.admin.attributes[USER_ATTRIBUTE_CHANGE_USERNAME] = False
|
||||||
|
self.admin.save()
|
||||||
|
self.client.force_login(self.admin)
|
||||||
|
response = self.client.put(
|
||||||
|
reverse("authentik_api:user-update-self"), data={"username": "foo", "name": "foo"}
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 400)
|
||||||
|
|
||||||
|
def test_update_self_email_denied(self):
|
||||||
|
"""Test update_self"""
|
||||||
|
self.admin.attributes[USER_ATTRIBUTE_CHANGE_EMAIL] = False
|
||||||
|
self.admin.save()
|
||||||
|
self.client.force_login(self.admin)
|
||||||
|
response = self.client.put(
|
||||||
|
reverse("authentik_api:user-update-self"), data={"email": "foo", "name": "foo"}
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 400)
|
||||||
|
|
||||||
def test_metrics(self):
|
def test_metrics(self):
|
||||||
"""Test user's metrics"""
|
"""Test user's metrics"""
|
||||||
self.client.force_login(self.admin)
|
self.client.force_login(self.admin)
|
||||||
@ -27,3 +58,114 @@ class TestUsersAPI(APITestCase):
|
|||||||
reverse("authentik_api:user-metrics", kwargs={"pk": self.user.pk})
|
reverse("authentik_api:user-metrics", kwargs={"pk": self.user.pk})
|
||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
|
def test_recovery_no_flow(self):
|
||||||
|
"""Test user recovery link (no recovery flow set)"""
|
||||||
|
self.client.force_login(self.admin)
|
||||||
|
response = self.client.get(
|
||||||
|
reverse("authentik_api:user-recovery", kwargs={"pk": self.user.pk})
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 404)
|
||||||
|
|
||||||
|
def test_recovery(self):
|
||||||
|
"""Test user recovery link (no recovery flow set)"""
|
||||||
|
flow = Flow.objects.create(
|
||||||
|
name="test", title="test", slug="test", designation=FlowDesignation.RECOVERY
|
||||||
|
)
|
||||||
|
tenant: Tenant = Tenant.objects.first()
|
||||||
|
tenant.flow_recovery = flow
|
||||||
|
tenant.save()
|
||||||
|
self.client.force_login(self.admin)
|
||||||
|
response = self.client.get(
|
||||||
|
reverse("authentik_api:user-recovery", kwargs={"pk": self.user.pk})
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_recovery_email_no_flow(self):
|
||||||
|
"""Test user recovery link (no recovery flow set)"""
|
||||||
|
self.client.force_login(self.admin)
|
||||||
|
response = self.client.get(
|
||||||
|
reverse("authentik_api:user-recovery-email", kwargs={"pk": self.user.pk})
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 404)
|
||||||
|
self.user.email = "foo@bar.baz"
|
||||||
|
self.user.save()
|
||||||
|
response = self.client.get(
|
||||||
|
reverse("authentik_api:user-recovery-email", kwargs={"pk": self.user.pk})
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 404)
|
||||||
|
|
||||||
|
def test_recovery_email_no_stage(self):
|
||||||
|
"""Test user recovery link (no email stage)"""
|
||||||
|
self.user.email = "foo@bar.baz"
|
||||||
|
self.user.save()
|
||||||
|
flow = Flow.objects.create(
|
||||||
|
name="test", title="test", slug="test", designation=FlowDesignation.RECOVERY
|
||||||
|
)
|
||||||
|
tenant: Tenant = Tenant.objects.first()
|
||||||
|
tenant.flow_recovery = flow
|
||||||
|
tenant.save()
|
||||||
|
self.client.force_login(self.admin)
|
||||||
|
response = self.client.get(
|
||||||
|
reverse("authentik_api:user-recovery-email", kwargs={"pk": self.user.pk})
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 404)
|
||||||
|
|
||||||
|
def test_recovery_email(self):
|
||||||
|
"""Test user recovery link"""
|
||||||
|
self.user.email = "foo@bar.baz"
|
||||||
|
self.user.save()
|
||||||
|
flow = Flow.objects.create(
|
||||||
|
name="test", title="test", slug="test", designation=FlowDesignation.RECOVERY
|
||||||
|
)
|
||||||
|
tenant: Tenant = Tenant.objects.first()
|
||||||
|
tenant.flow_recovery = flow
|
||||||
|
tenant.save()
|
||||||
|
|
||||||
|
stage = EmailStage.objects.create(name="email")
|
||||||
|
|
||||||
|
self.client.force_login(self.admin)
|
||||||
|
response = self.client.get(
|
||||||
|
reverse(
|
||||||
|
"authentik_api:user-recovery-email",
|
||||||
|
kwargs={"pk": self.user.pk},
|
||||||
|
)
|
||||||
|
+ f"?email_stage={stage.pk}"
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 204)
|
||||||
|
|
||||||
|
def test_service_account(self):
|
||||||
|
"""Service account creation"""
|
||||||
|
self.client.force_login(self.admin)
|
||||||
|
response = self.client.post(reverse("authentik_api:user-service-account"))
|
||||||
|
self.assertEqual(response.status_code, 400)
|
||||||
|
response = self.client.post(
|
||||||
|
reverse("authentik_api:user-service-account"),
|
||||||
|
data={
|
||||||
|
"name": "test-sa",
|
||||||
|
"create_group": True,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertTrue(User.objects.filter(username="test-sa").exists())
|
||||||
|
|
||||||
|
def test_service_account_invalid(self):
|
||||||
|
"""Service account creation (twice with same name, expect error)"""
|
||||||
|
self.client.force_login(self.admin)
|
||||||
|
response = self.client.post(
|
||||||
|
reverse("authentik_api:user-service-account"),
|
||||||
|
data={
|
||||||
|
"name": "test-sa",
|
||||||
|
"create_group": True,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertTrue(User.objects.filter(username="test-sa").exists())
|
||||||
|
response = self.client.post(
|
||||||
|
reverse("authentik_api:user-service-account"),
|
||||||
|
data={
|
||||||
|
"name": "test-sa",
|
||||||
|
"create_group": True,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 400)
|
||||||
|
@ -12,7 +12,7 @@ from authentik.core.views.session import EndSessionView
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path(
|
path(
|
||||||
"",
|
"",
|
||||||
login_required(RedirectView.as_view(pattern_name="authentik_core:if-admin")),
|
login_required(RedirectView.as_view(pattern_name="authentik_core:if-user")),
|
||||||
name="root-redirect",
|
name="root-redirect",
|
||||||
),
|
),
|
||||||
# Impersonation
|
# Impersonation
|
||||||
@ -32,6 +32,11 @@ urlpatterns = [
|
|||||||
ensure_csrf_cookie(TemplateView.as_view(template_name="if/admin.html")),
|
ensure_csrf_cookie(TemplateView.as_view(template_name="if/admin.html")),
|
||||||
name="if-admin",
|
name="if-admin",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"if/user/",
|
||||||
|
ensure_csrf_cookie(TemplateView.as_view(template_name="if/user.html")),
|
||||||
|
name="if-user",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"if/flow/<slug:flow_slug>/",
|
"if/flow/<slug:flow_slug>/",
|
||||||
ensure_csrf_cookie(FlowInterfaceView.as_view()),
|
ensure_csrf_cookie(FlowInterfaceView.as_view()),
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user