feat: add builder

This commit is contained in:
Georg K
2023-01-10 02:32:33 +03:00
parent e1c4663125
commit e9496d98b9
14 changed files with 480 additions and 0 deletions

6
.dockerignore Normal file
View File

@@ -0,0 +1,6 @@
.git/
.idea/
*.md
.kube/
build/
.kube/

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
.idea/
pkg/
bin/

View File

@@ -1,7 +1,25 @@
variables:
CI_REGISTRY: registry.connectone.pro
CONTAINER_IMAGE: ${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_BUILD_REF_NAME}_${CI_BUILD_REF}
stages: stages:
- release
- deploy
- release-deb - release-deb
- release-hosted - release-hosted
release:
stage: release
image: docker:latest
before_script:
- docker login -u gitlab-ci-token -p ${CI_BUILD_TOKEN} ${CI_REGISTRY}
script:
- docker build -t ${CONTAINER_IMAGE} .
- docker push ${CONTAINER_IMAGE}
only:
- develop
- main
release-deb: release-deb:
stage: release-deb stage: release-deb
image: docker:latest image: docker:latest
@@ -26,5 +44,40 @@ release-hosted:
- tar -czvf hosted.tar.gz hosted - tar -czvf hosted.tar.gz hosted
- 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file hosted.tar.gz "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/hosted/${VERSION}/hosted.tar.gz"' - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file hosted.tar.gz "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/hosted/${VERSION}/hosted.tar.gz"'
when: manual when: manual
only:
- main
deploy-staging:
stage: deploy
image: jar3b/deploh:${STAGING_DEPLOYER_VERSION}
variables:
KUBECONFIG_BASE64: ${STAGING_KUBECONFIG}
KUBECONFIG_CONTEXT_NAME: ${STAGING_KUBECONFIG_CONTEXT}
NAMESPACE: ${STAGING_NAMESPACE}
MAIN_DOMAIN: ${STAGING_MAIN_DOMAIN}
STORAGE_BASE: ${STAGING_STORAGE_BASE}
script:
- he.sh . ${NAMESPACE} "freeradius" --set db.password=${PG_PROD_PASS}
environment:
name: staging
only:
- develop
deploy-production:
stage: deploy
image: jar3b/deploh:${PRODUCTION_DEPLOYER_VERSION}
variables:
KUBECONFIG_BASE64: ${PRODUCTION_KUBECONFIG}
KUBECONFIG_CONTEXT_NAME: ${PRODUCTION_KUBECONFIG_CONTEXT}
NAMESPACE: ${PRODUCTION_NAMESPACE}
MAIN_DOMAIN: ${PRODUCTION_MAIN_DOMAIN}
STORAGE_BASE: ${PRODUCTION_STORAGE_BASE}
script:
- he.sh . ${NAMESPACE} "freeradius" --set db.password=${PG_PROD_PASS}
environment:
name: production
when: manual
only: only:
- main - main

4
.kube/Chart.yaml Normal file
View File

@@ -0,0 +1,4 @@
apiVersion: v2
name: freeradius
version: 1.0.1
appVersion: 3.2.0

View File

@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: {{.Release.Name}}-registry-key
namespace: {{.Release.Namespace}}
data:
.dockerconfigjson: "{{.Values.registryAuthBase64}}"
type: kubernetes.io/dockerconfigjson

View File

@@ -0,0 +1,168 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configs
namespace: {{ .Release.Namespace }}
labels:
app: clickhouse-operator
data:
default: |
server default {
listen {
type = auth
ipaddr = *
port = {{.Values.ports.main}}
limit {
max_connections = 16
lifetime = 0
idle_timeout = 30
}
}
listen {
ipaddr = *
port = {{.Values.ports.second}}
type = acct
limit {
}
}
authorize {
filter_username
preprocess
chap
mschap
digest
expiration
logintime
pap
Autz-Type New-TLS-Connection {
ok
}
}
authenticate {
Auth-Type PAP {
pap
}
Auth-Type CHAP {
chap
}
digest
}
preacct {
preprocess
acct_unique
suffix
files
}
accounting {
detail
unix
-sql
exec
attr_filter.accounting_response
}
session {
}
post-auth {
if (session-state:User-Name && reply:User-Name && request:User-Name && (reply:User-Name == request:User-Name)) {
update reply {
&User-Name !* ANY
}
}
update {
&reply: += &session-state:
}
-sql
exec
remove_reply_message_if_eap
Post-Auth-Type REJECT {
-sql
attr_filter.access_reject
remove_reply_message_if_eap
}
Post-Auth-Type Client-Lost {
}
if (EAP-Key-Name && &reply:EAP-Session-Id) {
update reply {
&EAP-Key-Name := &reply:EAP-Session-Id
}
}
}
pre-proxy {
}
post-proxy {
}
}
sql: |
sql {
dialect = "postgresql"
driver = "rlm_sql_${dialect}"
postgresql {
send_application_name = yes
}
server = "{{.Values.db.host}}"
port = {{.Values.db.port}}
login = "{{.Values.db.user}}"
password = "{{.Values.db.password}}"
radius_db = "{{.Values.db.name}}"
acct_table1 = "radacct"
acct_table2 = "radacct"
postauth_table = "radpostauth"
authcheck_table = "radcheck"
groupcheck_table = "radgroupcheck"
authreply_table = "radreply"
groupreply_table = "radgroupreply"
usergroup_table = "radusergroup"
delete_stale_sessions = yes
pool {
start = ${thread[pool].start_servers}
min = ${thread[pool].min_spare_servers}
max = ${thread[pool].max_servers}
spare = ${thread[pool].max_spare_servers}
uses = 0
retry_delay = 30
lifetime = 0
idle_timeout = 60
}
client_table = "nas"
group_attribute = "SQL-Group"
$INCLUDE ${modconfdir}/${.:name}/main/${dialect}/queries.conf
}
rest: |
rest {
tls {
}
connect_uri = "http://{{.Values.api.host}}:{{.Values.api.port}}/"
authorize {
uri = "${..connect_uri}radius/auth"
method = 'post'
body = 'json'
data = '{"ip": "%{Packet-Src-IP-Address}", "hotspot-group": "%{raw:Called-Station-Id}", "hotspot-id": "%{raw:NAS-Identifier}"}'
force_to = 'json'
auth = 'none'
require_auth = no
timeout = 4.000000
}
pool {
start = ${thread[pool].start_servers}
min = ${thread[pool].min_spare_servers}
max = ${thread[pool].max_servers}
spare = ${thread[pool].max_spare_servers}
uses = 0
retry_delay = 30
lifetime = 0
idle_timeout = 60
}
}

View File

@@ -0,0 +1,69 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{.Release.Name}}
namespace: {{.Release.Namespace}}
spec:
replicas: 1
selector:
matchLabels:
app: {{.Release.Name}}
template:
metadata:
labels:
app: {{.Release.Name}}
spec:
nodeSelector:
freeradius: enabled
tolerations:
- key: freeradius
operator: Equal
value: enabled
effect: NoSchedule
imagePullSecrets:
- name: {{.Release.Name}}-registry-key
{{/* securityContext:*/}}
{{/* runAsUser: 108*/}}
{{/* runAsGroup: 112*/}}
{{/* fsGroup: 108*/}}
containers:
- name: {{.Release.Name}}
image: {{.Values.image.name}}
imagePullPolicy: {{.Values.image.pullPolicy}}
env:
- name: MY_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: TZ
value: UTC
- name: HOSTNAME
value: freeradius
ports:
- containerPort: {{.Values.ports.main}}
- containerPort: {{.Values.ports.second}}
volumeMounts:
- mountPath: /etc/freeradius/certs
name: freeradius-cert-data
readOnly: false
- name: configs-volume
mountPath: "/configs/default"
subPath: default
readOnly: true
- name: configs-volume
mountPath: "/configs/sql"
subPath: sql
readOnly: true
- name: configs-volume
mountPath: "/configs/rest"
subPath: rest
readOnly: true
volumes:
- name: configs-volume
configMap:
name: {{ .Release.Name }}-configs
defaultMode: 488
- name: freeradius-cert-data
persistentVolumeClaim:
claimName: freeradius-data-claim

View File

@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: {{.Release.Name}}-external
namespace: {{.Release.Namespace}}
spec:
type: NodePort
externalTrafficPolicy: Local
ports:
- port: {{.Values.ports.main}}
nodePort: {{.Values.ports.main}}
protocol: UDP
name: freerad-first
- port: {{.Values.ports.second}}
nodePort: {{.Values.ports.second}}
protocol: UDP
name: freerad-second
selector:
app: {{ .Chart.Name }}

View File

@@ -0,0 +1,26 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: freeradius-data-disk
namespace: {{.Release.Namespace}}
spec:
capacity:
storage: 10Mi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
hostPath:
path: {{.Values.storageBase}}/{{.Chart.Name}}
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: freeradius-data-claim
namespace: {{.Release.Namespace}}
spec:
volumeName: freeradius-data-disk
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Mi

20
.kube/values.yaml Normal file
View File

@@ -0,0 +1,20 @@
image:
name: ${CONTAINER_IMAGE}
pullPolicy: "IfNotPresent"
registryAuthBase64: ${REGISTRY_AUTH}
storageBase: ${STORAGE_BASE}
ports:
main: 31812
second: 31813
db:
host: "postgresql-pgbouncer"
port: 6432
user: "admin"
password: "radius_db"
name: "radius_db"
api:
host: "hotspotter"
port: 8080

30
Dockerfile Normal file
View File

@@ -0,0 +1,30 @@
FROM ubuntu:18.04
WORKDIR /tmp
ARG out_dir=/etc/freeradius
COPY local-bionic.list /etc/apt/sources.list
RUN apt-get update && apt-get install -y apt-transport-https ca-certificates curl software-properties-common gpg
RUN curl -fsSL http://connectone.pro/gpg | gpg --dearmor -o /usr/share/keyrings/connectone.gpg && \
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/connectone.gpg] \
https://nexus.connectone.pro/repository/radius bionic main" | tee /etc/apt/sources.list.d/connectone.list \
> /dev/null
RUN apt-get update && apt-get install -y libfreeradius3=3.2.2+git freeradius-common=3.2.2+git \
freeradius-postgresql=3.2.2+git freeradius-rest=3.2.2+git freeradius-utils=3.2.2+git freeradius=3.2.2+git && \
apt autoremove --purge -y && apt-get clean
COPY hosted /tmp/hosted
RUN cp hosted/config/radiusd.conf $out_dir/radiusd.conf && \
cp hosted/config/dictionary $out_dir/dictionary && \
cp hosted/config/clients.conf $out_dir/clients.conf && \
cp hosted/config/mods-enabled/raw $out_dir/mods-enabled/raw && \
cp hosted/config/sites-enabled/dynamic-clients $out_dir/sites-enabled/dynamic-clients && \
rm -f /etc/freeradius/sites-enabled/inner-tunnel && \
rm -f /etc/freeradius/mods-enabled/eap \
RUN rm -f /etc/freeradius/mods-enabled/delay && \
ln -s $out_dir/mods-available/delay $out_dir/mods-enabled/delay
ADD entrypoint.sh /bin/entrypoint.sh
RUN chmod a+x /bin/entrypoint.sh && chmod -R 750 $out_dir && chown -R freerad:root $out_dir && \
mv /etc/freeradius/certs /tmp && \
rm -rf /tmp/hosted
WORKDIR /etc/freeradius
ENTRYPOINT ["entrypoint.sh"]
CMD ["freeradius", "-f"]

View File

@@ -5,4 +5,9 @@ build:
cd build cd build
docker build . -t freerad_builder:3.2.x -f Dockerfile_build docker build . -t freerad_builder:3.2.x -f Dockerfile_build
docker run -e DEB_USER=${DEB_USER} DEB_PASS="${DEB_PASS}" freerad_builder:3.2.x ./upload.sh docker run -e DEB_USER=${DEB_USER} DEB_PASS="${DEB_PASS}" freerad_builder:3.2.x ./upload.sh
```
label nodes:
```bash
kubectl label node connect-prod-0 freeradius=enabled
``` ```

20
entrypoint.sh Normal file
View File

@@ -0,0 +1,20 @@
#!/bin/bash
echo "copy configs"
cp -r /configs/default /etc/freeradius/sites-enabled/default
cp -r /configs/sql /etc/freeradius/mods-enabled/sql
cp -r /configs/rest /etc/freeradius/mods-enabled/rest
if [ ! "$(ls -A /etc/freeradius/certs)" ]; then
echo "Copying certificates"
mkdir -p /etc/freeradius/certs/
cp -r /tmp/certs/ /etc/freeradius/certs/
fi
echo "chowning..."
chown -R freerad:root /etc/freeradius && chmod -R 750 /etc/freeradius
echo "running"
exec "$@"

49
local-bionic.list Normal file
View File

@@ -0,0 +1,49 @@
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirror.yandex.ru/ubuntu/ bionic main restricted
# deb-src http://mirror.yandex.ru/ubuntu/ bionic main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://mirror.yandex.ru/ubuntu/ bionic-updates main restricted
# deb-src http://mirror.yandex.ru/ubuntu/ bionic-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://mirror.yandex.ru/ubuntu/ bionic universe
# deb-src http://mirror.yandex.ru/ubuntu/ bionic universe
deb http://mirror.yandex.ru/ubuntu/ bionic-updates universe
# deb-src http://mirror.yandex.ru/ubuntu/ bionic-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://mirror.yandex.ru/ubuntu/ bionic multiverse
# deb-src http://mirror.yandex.ru/ubuntu/ bionic multiverse
deb http://mirror.yandex.ru/ubuntu/ bionic-updates multiverse
# deb-src http://mirror.yandex.ru/ubuntu/ bionic-updates multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://mirror.yandex.ru/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src http://mirror.yandex.ru/ubuntu/ bionic-backports main restricted universe multiverse
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu bionic partner
# deb-src http://archive.canonical.com/ubuntu bionic partner
deb http://security.ubuntu.com/ubuntu/ bionic-security main restricted
# deb-src http://security.ubuntu.com/ubuntu/ bionic-security main restricted
deb http://security.ubuntu.com/ubuntu/ bionic-security universe
# deb-src http://security.ubuntu.com/ubuntu/ bionic-security universe
deb http://security.ubuntu.com/ubuntu/ bionic-security multiverse
# deb-src http://security.ubuntu.com/ubuntu/ bionic-security multiverse