commit
25b78d4a0f
@ -0,0 +1,3 @@
|
||||
# gitea
|
||||
|
||||
OIDC setup is now automated
|
@ -0,0 +1,45 @@
|
||||
version: "3"
|
||||
|
||||
networks:
|
||||
gitea:
|
||||
external: false
|
||||
|
||||
services:
|
||||
gitea:
|
||||
image: gitea/gitea:1.16.6
|
||||
env_file:
|
||||
- ../env.production
|
||||
- env.production
|
||||
- ../data/gitea/env.secrets
|
||||
environment:
|
||||
- USER_UID=1000
|
||||
- USER_GID=1000
|
||||
- GITEA__database__DB_TYPE=postgres
|
||||
- GITEA__database__HOST=db:5432
|
||||
- GITEA__database__NAME=gitea
|
||||
- GITEA__database__USER=gitea
|
||||
- GITEA__database__PASSWD=gitea
|
||||
networks:
|
||||
- gitea
|
||||
volumes:
|
||||
- ../data/gitea:/data
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
ports:
|
||||
- "3030:3000"
|
||||
- "222:22"
|
||||
restart: always
|
||||
depends_on:
|
||||
- db
|
||||
|
||||
db:
|
||||
image: postgres:13.4-alpine
|
||||
restart: always
|
||||
environment:
|
||||
- POSTGRES_USER=gitea
|
||||
- POSTGRES_PASSWORD=gitea
|
||||
- POSTGRES_DB=gitea
|
||||
volumes:
|
||||
- ../data/gitea/postgres:/var/lib/postgresql/data
|
||||
networks:
|
||||
- gitea
|
@ -0,0 +1,6 @@
|
||||
# gitea config for keycloak integration
|
||||
# only allow open id sign-in, turn off all other registrations
|
||||
GITEA__openid__ENABLE_OPENID_SIGNIN=true
|
||||
GITEA__openid__ENABLE_OPENID_SIGNUP=false
|
||||
#GITEA__service__DISABLE_REGISTRATION=true
|
||||
GITEA__service__ALLOW_ONLY_EXTERNAL_REGISTRATION=true
|
@ -0,0 +1,67 @@
|
||||
#!/bin/bash
|
||||
die() { echo >&2 "gitea: ERROR $*" ; exit 1 ; }
|
||||
info() { echo >&2 "gitea: $*" ; }
|
||||
|
||||
DIRNAME="$(dirname $0)"
|
||||
cd "$DIRNAME"
|
||||
|
||||
source ../env.production || die "no top level environment"
|
||||
source ./env.production || die "no local environment"
|
||||
|
||||
DATA="../data/gitea"
|
||||
SECRETS="$DATA/env.secrets"
|
||||
INI="$DATA/gitea/conf/app.ini"
|
||||
|
||||
if [ -r "$SECRETS" ]; then
|
||||
docker-compose up -d || die "unable to start"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
GITEA_CLIENT_SECRET="$(openssl rand -hex 32)"
|
||||
GITEA_ADMIN_PASSWORD="$(openssl rand -hex 8)"
|
||||
|
||||
info "creating new secrets $SECRETS"
|
||||
|
||||
mkdir -p "$DATA"
|
||||
cat <<EOF > "$SECRETS"
|
||||
# DO NOT CHECK IN
|
||||
GITEA_CLIENT_SECRET=$GITEA_CLIENT_SECRET
|
||||
GITEA_ADMIN_PASSWORD=$GITEA_ADMIN_PASSWORD
|
||||
GITEA__server__ROOT_URL=https://$GITEA_HOSTNAME/
|
||||
GITEA__security__INSTALL_LOCK=true
|
||||
GITEA__security__SECRET_KEY=$(openssl rand -hex 32)
|
||||
EOF
|
||||
|
||||
|
||||
docker-compose down 2>/dev/null
|
||||
|
||||
../keycloak/client-delete gitea 2>/dev/null
|
||||
../keycloak/client-create <<EOF || die "unable to create gitea client"
|
||||
{
|
||||
"clientId": "gitea",
|
||||
"rootUrl": "https://$GITEA_HOSTNAME",
|
||||
"adminUrl": "https://$GITEA_HOSTNAME",
|
||||
"redirectUris": [ "https://$GITEA_HOSTNAME/*" ],
|
||||
"webOrigins": [ "https://$GITEA_HOSTNAME" ],
|
||||
"clientAuthenticatorType": "client-secret",
|
||||
"secret": "$GITEA_CLIENT_SECRET"
|
||||
}
|
||||
EOF
|
||||
|
||||
docker-compose up -d || die "unable to start container"
|
||||
|
||||
info "waiting for startup..."
|
||||
sleep 5
|
||||
|
||||
info "adding oauth login"
|
||||
docker-compose exec -u git gitea \
|
||||
gitea admin auth add-oauth \
|
||||
--name "keycloak" \
|
||||
--provider "openidConnect" \
|
||||
--key "gitea" \
|
||||
--secret "$GITEA_CLIENT_SECRET" \
|
||||
--auto-discover-url "https://${KEYCLOAK_HOSTNAME}/realms/${REALM}/.well-known/openid-configuration" \
|
||||
--group-claim-name "groups" \
|
||||
--admin-group "admin" \
|
||||
|| die "unable to add oauth interface"
|
@ -0,0 +1,37 @@
|
||||
server {
|
||||
server_name ${GITEA_HOSTNAME};
|
||||
client_max_body_size 128m;
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
types_hash_max_size 2048;
|
||||
|
||||
gzip on;
|
||||
gzip_disable "msie6";
|
||||
|
||||
proxy_read_timeout 1800s;
|
||||
|
||||
location / {
|
||||
proxy_pass http://host.docker.internal:3030;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# force login with OIDC
|
||||
location /user/login {
|
||||
return 302 https://${GITEA_HOSTNAME}/user/oauth2/keycloak;
|
||||
}
|
||||
|
||||
listen 443 ssl;
|
||||
ssl_certificate /etc/letsencrypt/live/${DOMAIN_NAME}/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/${DOMAIN_NAME}/privkey.pem;
|
||||
include /etc/nginx/includes/options-ssl-nginx.conf;
|
||||
include /etc/nginx/includes/challenge.conf;
|
||||
ssl_dhparam /etc/nginx/includes/ssl-dhparams.pem;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in new issue