Skip to content

Commit 44e9a0d

Browse files
committed
new scripts for Authentik
1 parent 6d915bf commit 44e9a0d

File tree

3 files changed

+342
-0
lines changed

3 files changed

+342
-0
lines changed

ct/authentik.sh

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/usr/bin/env bash
2+
source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)
3+
# Copyright (c) 2021-2024 tteck
4+
# Author: tteck (tteckster)
5+
# Co-Author: remz1337
6+
# License: MIT
7+
# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
8+
9+
function header_info {
10+
clear
11+
cat <<"EOF"
12+
___ __ __ __ _ __
13+
/ | __ __/ /_/ /_ ___ ____ / /_(_) /__
14+
/ /| |/ / / / __/ __ \/ _ \/ __ \/ __/ / //_/
15+
/ ___ / /_/ / /_/ / / / __/ / / / /_/ / ,<
16+
/_/ |_\__,_/\__/_/ /_/\___/_/ /_/\__/_/_/|_|
17+
18+
EOF
19+
}
20+
header_info
21+
echo -e "Loading..."
22+
APP="Authentik"
23+
var_disk="12"
24+
var_cpu="6"
25+
var_ram="8192"
26+
var_os="debian"
27+
var_version="12"
28+
variables
29+
color
30+
catch_errors
31+
32+
function default_settings() {
33+
CT_TYPE="1"
34+
PW=""
35+
CT_ID=$NEXTID
36+
HN=$NSAPP
37+
DISK_SIZE="$var_disk"
38+
CORE_COUNT="$var_cpu"
39+
RAM_SIZE="$var_ram"
40+
BRG="vmbr0"
41+
NET="dhcp"
42+
GATE=""
43+
APT_CACHER=""
44+
APT_CACHER_IP=""
45+
DISABLEIP6="no"
46+
MTU=""
47+
SD=""
48+
NS=""
49+
MAC=""
50+
VLAN=""
51+
SSH="no"
52+
VERB="no"
53+
echo_default
54+
}
55+
56+
function update_script() {
57+
header_info
58+
check_container_storage
59+
check_container_resources
60+
if [[ ! -f /etc/systemd/system/authentik-server.service ]]; then msg_error "No ${APP} Installation Found!"; exit; fi
61+
RELEASE=$(curl -s https://api.github.com/repos/goauthentik/authentik/releases/latest | grep "tarball_url" | awk '{print substr($2, 2, length($2)-3)}')
62+
if [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then
63+
whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox --title "SET RESOURCES" "Please set the resources in your ${APP} LXC to ${var_cpu}vCPU and ${var_ram}RAM for the build process before continuing" 10 75
64+
msg_info "Stopping Authentik"
65+
systemctl stop authentik-server
66+
systemctl stop authentik-worker
67+
msg_ok "Stopped Authentik"
68+
69+
msg_info "Building Authentik website"
70+
mkdir -p /opt/authentik
71+
wget -qO authentik.tar.gz "${RELEASE}"
72+
tar -xzf authentik.tar.gz -C /opt/authentik --strip-components 1 --overwrite
73+
rm -rf authentik.tar.gz
74+
cd /opt/authentik/website
75+
npm install >/dev/null 2>&1
76+
npm run build-bundled >/dev/null 2>&1
77+
cd /opt/authentik/web
78+
npm install >/dev/null 2>&1
79+
npm run build >/dev/null 2>&1
80+
msg_ok "Built Authentik website"
81+
82+
msg_info "Installing Python Dependencies"
83+
cd /opt/authentik
84+
poetry install --only=main --no-ansi --no-interaction --no-root >/dev/null 2>&1
85+
poetry export --without-hashes --without-urls -f requirements.txt --output requirements.txt >/dev/null 2>&1
86+
pip install --no-cache-dir -r requirements.txt >/dev/null 2>&1
87+
pip install . >/dev/null 2>&1
88+
msg_ok "Installed Python Dependencies"
89+
90+
msg_info "Updating ${APP} to v${RELEASE} (Patience)"
91+
cp -r /opt/authentik/authentik/blueprints /opt/authentik/blueprints
92+
cd /opt/authentik
93+
bash /opt/authentik/lifecycle/ak migrate >/dev/null 2>&1
94+
echo "${RELEASE}" >/opt/${APP}_version.txt
95+
msg_ok "Updated ${APP} to v${RELEASE}"
96+
97+
msg_info "Starting Authentik"
98+
systemctl start authentik-server
99+
systemctl start authentik-worker
100+
msg_ok "Started Authentik"
101+
echo -e "\n ⚠️ Ensure you set resources back to normal settings \n"
102+
else
103+
msg_ok "No update required. ${APP} is already at ${RELEASE}"
104+
fi
105+
exit
106+
}
107+
108+
start
109+
build_container
110+
description
111+
112+
msg_info "Setting Container to Normal Resources"
113+
pct set $CTID -memory 1024
114+
pct set $CTID -cores 2
115+
msg_ok "Set Container to Normal Resources"
116+
msg_ok "Completed Successfully!\n"
117+
echo -e "${APP} should be reachable by going to the following URL.
118+
${BL}http://${IP}:9000/if/flow/initial-setup/${CL} \n"

install/authentik-install.sh

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (c) 2021-2024 tteck
4+
# Author: tteck (tteckster)
5+
# Co-Author: remz1337
6+
# License: MIT
7+
# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
8+
9+
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
10+
color
11+
verb_ip6
12+
catch_errors
13+
setting_up_container
14+
network_check
15+
update_os
16+
17+
msg_info "Installing Dependencies (Patience)"
18+
$STD apt-get install -y {curl,sudo,mc}
19+
$STD apt-get install -y gpg pkg-config libffi-dev
20+
$STD apt-get install -y --no-install-recommends build-essential libpq-dev libkrb5-dev
21+
$STD apt-get install -y libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev pkg-config libffi-dev zlib1g-dev libxmlsec1 libxmlsec1-dev libxmlsec1-openssl libmaxminddb0
22+
msg_ok "Installed Dependencies"
23+
24+
msg_info "Installing yq"
25+
YQ_LATEST="$(wget -qO- "https://api.github.com/repos/mikefarah/yq/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")')"
26+
$STD wget "https://github.com/mikefarah/yq/releases/download/${YQ_LATEST}/yq_linux_amd64" -qO /usr/bin/yq
27+
chmod +x /usr/bin/yq
28+
msg_ok "Installed yq"
29+
30+
msg_info "Installing Python 3.12"
31+
wget -q https://www.python.org/ftp/python/3.12.1/Python-3.12.1.tgz -O Python.tgz
32+
tar -zxf Python.tgz
33+
cd Python-3.12.1
34+
$STD ./configure --enable-optimizations
35+
$STD make altinstall
36+
$STD cd -
37+
$STD rm -rf Python-3.12.1
38+
$STD rm -rf Python.tgz
39+
$STD update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.12 1
40+
msg_ok "Installed Python 3.12"
41+
42+
NODE_VER="22"
43+
msg_info "Installing Node.js ${NODE_VER}"
44+
mkdir -p /etc/apt/keyrings
45+
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
46+
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_VER}.x nodistro main" >/etc/apt/sources.list.d/nodesource.list
47+
$STD apt-get update
48+
$STD apt-get install -y nodejs
49+
msg_ok "Installed Node.js ${NODE_VER}"
50+
51+
msg_info "Building Authentik website"
52+
RELEASE=$(curl -s https://api.github.com/repos/goauthentik/authentik/releases/latest | grep "tarball_url" | awk '{print substr($2, 2, length($2)-3)}')
53+
mkdir -p /opt/authentik
54+
$STD wget -qO authentik.tar.gz "${RELEASE}"
55+
tar -xzf authentik.tar.gz -C /opt/authentik --strip-components 1 --overwrite
56+
rm -rf authentik.tar.gz
57+
cd /opt/authentik/website
58+
$STD npm install
59+
$STD npm run build-bundled
60+
cd /opt/authentik/web
61+
$STD npm install
62+
$STD npm run build
63+
echo "${RELEASE}" >/opt/${APPLICATION}_version.txt
64+
msg_ok "Built Authentik website"
65+
66+
msg_info "Installing Golang"
67+
cd ~
68+
set +o pipefail
69+
GO_RELEASE=$(curl -s https://go.dev/dl/ | grep -o -m 1 "go.*\linux-amd64.tar.gz")
70+
$STD wget -q https://golang.org/dl/${GO_RELEASE}
71+
tar -xzf ${GO_RELEASE} -C /usr/local
72+
$STD ln -s /usr/local/go/bin/go /usr/bin/go
73+
rm -rf go/
74+
rm -rf ${GO_RELEASE}
75+
set -o pipefail
76+
msg_ok "Installed Golang"
77+
78+
msg_info "Building Go Proxy"
79+
cd /opt/authentik
80+
$STD go mod download
81+
$STD go build -o /go/authentik ./cmd/server
82+
$STD go build -o /opt/authentik/authentik-server /opt/authentik/cmd/server/
83+
msg_ok "Built Go Proxy"
84+
85+
msg_info "Installing GeoIP"
86+
cd ~
87+
GEOIP_RELEASE=$(curl -s https://api.github.com/repos/maxmind/geoipupdate/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
88+
$STD wget -qO geoipupdate.deb https://github.com/maxmind/geoipupdate/releases/download/v${GEOIP_RELEASE}/geoipupdate_${GEOIP_RELEASE}_linux_amd64.deb
89+
$STD dpkg -i geoipupdate.deb
90+
rm geoipupdate.deb
91+
cat <<EOF >/etc/GeoIP.conf
92+
#GEOIPUPDATE_EDITION_IDS="GeoLite2-City GeoLite2-ASN"
93+
#GEOIPUPDATE_VERBOSE="1"
94+
#GEOIPUPDATE_ACCOUNT_ID_FILE="/run/secrets/GEOIPUPDATE_ACCOUNT_ID"
95+
#GEOIPUPDATE_LICENSE_KEY_FILE="/run/secrets/GEOIPUPDATE_LICENSE_KEY"
96+
EOF
97+
msg_ok "Installed GeoIP"
98+
99+
msg_info "Installing Python Dependencies"
100+
cd /opt/authentik
101+
$STD apt install -y python3-pip
102+
$STD apt install -y git
103+
$STD pip3 install --upgrade pip
104+
$STD pip3 install poetry poetry-plugin-export
105+
$STD ln -s /usr/local/bin/poetry /usr/bin/poetry
106+
$STD poetry install --only=main --no-ansi --no-interaction --no-root
107+
$STD poetry export --without-hashes --without-urls -f requirements.txt --output requirements.txt
108+
$STD pip install --no-cache-dir -r requirements.txt
109+
$STD pip install .
110+
msg_ok "Installed Python Dependencies"
111+
112+
msg_info "Installing Redis"
113+
$STD apt install -y redis-server
114+
systemctl enable -q --now redis-server
115+
msg_ok "Installed Redis"
116+
117+
msg_info "Installing PostgreSQL"
118+
$STD apt install -y postgresql postgresql-contrib
119+
DB_NAME="authentik"
120+
DB_USER="authentik"
121+
DB_PASS="$(openssl rand -base64 18 | cut -c1-13)"
122+
$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME;"
123+
$STD sudo -u postgres psql -c "CREATE USER $DB_USER WITH PASSWORD '$DB_PASS';"
124+
$STD sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER;"
125+
$STD sudo -u postgres psql -c "ALTER DATABASE $DB_NAME OWNER TO $DB_USER;"
126+
$STD sudo -u postgres psql -c "ALTER USER $DB_USER WITH SUPERUSER;"
127+
msg_ok "Installed PostgreSQL"
128+
129+
msg_info "Installing Authentik"
130+
mkdir -p /etc/authentik
131+
cp /opt/authentik/authentik/lib/default.yml /opt/authentik/authentik/lib/default.yml.BAK
132+
mv /opt/authentik/authentik/lib/default.yml /etc/authentik/config.yml
133+
$STD yq -i ".secret_key = \"$(openssl rand -hex 32)\"" /etc/authentik/config.yml
134+
$STD yq -i ".postgresql.password = \"${DB_PASS}\"" /etc/authentik/config.yml
135+
$STD yq -i ".geoip = \"/opt/authentik/tests/GeoLite2-City-Test.mmdb\"" /etc/authentik/config.yml
136+
cp -r /opt/authentik/authentik/blueprints /opt/authentik/blueprints
137+
$STD yq -i ".blueprints_dir = \"/opt/authentik/blueprints\"" /etc/authentik/config.yml
138+
$STD apt install -y python-is-python3
139+
$STD ln -s /usr/local/bin/gunicorn /usr/bin/gunicorn
140+
$STD ln -s /usr/local/bin/celery /usr/bin/celery
141+
cd /opt/authentik
142+
$STD bash /opt/authentik/lifecycle/ak migrate
143+
msg_ok "Installed Authentik"
144+
145+
msg_info "Configuring Services"
146+
cat <<EOF >/etc/systemd/system/authentik-server.service
147+
[Unit]
148+
Description = Authentik Server
149+
[Service]
150+
ExecStart=/opt/authentik/authentik-server
151+
WorkingDirectory=/opt/authentik/
152+
#User=authentik
153+
#Group=authentik
154+
Restart=always
155+
RestartSec=5
156+
[Install]
157+
WantedBy=multi-user.target
158+
EOF
159+
systemctl enable -q --now authentik-server
160+
sleep 2
161+
cat <<EOF >/etc/systemd/system/authentik-worker.service
162+
[Unit]
163+
Description = Authentik Worker
164+
[Service]
165+
Environment=DJANGO_SETTINGS_MODULE="authentik.root.settings"
166+
ExecStart=celery -A authentik.root.celery worker -Ofair --max-tasks-per-child=1 --autoscale 3,1 -E -B -s /tmp/celerybeat-schedule -Q authentik,authentik_scheduled,authentik_events
167+
WorkingDirectory=/opt/authentik/authentik
168+
#User=authentik
169+
#Group=authentik
170+
Restart=always
171+
RestartSec=5
172+
[Install]
173+
WantedBy=multi-user.target
174+
EOF
175+
systemctl enable -q --now authentik-worker
176+
sleep 5
177+
msg_ok "Configured Services"
178+
179+
motd_ssh
180+
customize
181+
182+
msg_info "Cleaning up"
183+
$STD apt-get -y autoremove
184+
$STD apt-get -y autoclean
185+
msg_ok "Cleaned"

json/authentik.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "Authentik",
3+
"slug": "authentik",
4+
"categories": [
5+
11
6+
],
7+
"date_created": "2024-11-06",
8+
"type": "ct",
9+
"updateable": false,
10+
"privileged": false,
11+
"interface_port": "9000",
12+
"documentation": null,
13+
"website": "https://goauthentik.io/",
14+
"logo": "https://github.com/goauthentik/authentik/blob/main/website/static/img/icon.png",
15+
"description": "Authentik is an IdP (Identity Provider) and SSO (single sign on) that is built with security at the forefront of every piece of code, every feature, with an emphasis on flexibility and versatility.",
16+
"install_methods": [
17+
{
18+
"type": "default",
19+
"script": "ct/authentik.sh",
20+
"resources": {
21+
"cpu": "6",
22+
"ram": "8192",
23+
"hdd": "12",
24+
"os": "debian",
25+
"version": "12"
26+
}
27+
}
28+
],
29+
"default_credentials": {
30+
"username": null,
31+
"password": null
32+
},
33+
"notes": [
34+
{
35+
"text": "Initial configuration at http://<IP>:9000/if/flow/initial-setup/",
36+
"type": "warning"
37+
}
38+
]
39+
}

0 commit comments

Comments
 (0)