remote-challenge-sync-airbus: Pass arguments through metadata files

This commit is contained in:
nemunaire 2024-03-22 19:08:21 +01:00
parent 3c8ba3ecc2
commit 1e24d0ea25
3 changed files with 72 additions and 6 deletions

View File

@ -9,6 +9,9 @@ export IP_FIC_SRS_FR=$(host ${DOMAIN_NAME} | grep -o '\([0-9]\{1,3\}.\)\+')
export IPS_BACKEND="192.168.3.92/24\\n192.168.4.92/24"
export IP_BACKEND_ROUTER="192.168.3.1"
export AIRBUS_BASEURL="https://..."
export AIRBUS_TOKEN="abcdef0123456789abcdef0123456789"
export AIRBUS_SESSION_NAME="Forensique"
escape_newline () {
sed 's/$/\\n/g' | tr -d '\n'
@ -125,6 +128,22 @@ TEMPLATE='
}
}
},
"remote_sync": {
"entries": {
"baseurl": {
"perm": "0444",
"content": "${AIRBUS_BASEURL}"
},
"token": {
"perm": "0444",
"content": "${AIRBUS_TOKEN}"
},
"session_name": {
"perm": "0444",
"content": "${AIRBUS_SESSION_NAME}"
}
}
},
"tls_config": {
"entries": {
"dhparams-4096.pem": {

View File

@ -203,15 +203,14 @@ services:
- /var/lib/fic/submissions
- /var/lib/fic/teams
- name: fic-remote-challenge-sync-airbus
# image: nemunaire/fic-remote-challenge-sync-airbus:latest
image: alpine:3
command: ["/bin/ash", "-c", "while true; do sleep 300; done"]
image: nemunaire/fic-remote-challenge-sync-airbus:latest
env:
- AIRBUS_BASEURL=https://....
- AIRBUS_TOKEN=abcdef0123456789abcdef0123456789
- AIRBUS_SESSIONID=42
- AIRBUS_BASEURL_FILE=/run/config/remote_sync/baseurl
- AIRBUS_TOKEN_FILE=/run/config/remote_sync/token
- AIRBUS_SESSION_NAME_FILE=/run/config/remote_sync/session_name
binds:
- /etc/hosts:/etc/hosts:ro
- /run/config/remote-challenge-sync/:/run/config/remote-challenge-sync/:ro
- /var/lib/fic/teams:/srv/TEAMS:ro
- /var/lib/fic/remote:/srv/REMOTE
runtime:

View File

@ -45,6 +45,16 @@ func main() {
if v, exists := os.LookupEnv("AIRBUS_BASEURL"); exists {
api.BaseURL = v
} else if v, exists := os.LookupEnv("AIRBUS_BASEURL_FILE"); exists {
fd, err := os.Open(v)
if err != nil {
log.Fatal("Unable to open AIRBUS_BASEURL_FILE:", err)
}
b, _ := ioutil.ReadAll(fd)
api.BaseURL = strings.TrimSpace(string(b))
fd.Close()
}
if v, exists := os.LookupEnv("AIRBUS_SKIP_TLS_VERIFY"); exists {
var err error
@ -55,6 +65,16 @@ func main() {
}
if v, exists := os.LookupEnv("AIRBUS_TOKEN"); exists {
api.Token = v
} else if v, exists := os.LookupEnv("AIRBUS_TOKEN_FILE"); exists {
fd, err := os.Open(v)
if err != nil {
log.Fatal("Unable to open AIRBUS_TOKEN_FILE:", err)
}
b, _ := ioutil.ReadAll(fd)
api.Token = strings.TrimSpace(string(b))
fd.Close()
}
if v, exists := os.LookupEnv("AIRBUS_SESSIONID"); exists {
@ -63,6 +83,34 @@ func main() {
if err != nil {
log.Fatal("AIRBUS_SESSIONID is invalid: ", err.Error())
}
} else if v, exists := os.LookupEnv("AIRBUS_SESSION_NAME_FILE"); exists {
fd, err := os.Open(v)
if err != nil {
log.Fatal("Unable to open AIRBUS_SESSION_NAME_FILE:", err)
}
b, _ := ioutil.ReadAll(fd)
fd.Close()
v = strings.TrimSpace(string(b))
sessions, err := api.GetSessions()
if err != nil {
log.Fatal("Unable to retrieve session: ", err)
}
for _, session := range sessions {
if session.Name == v {
api.SessionID = session.ID
break
}
}
if api.SessionID == 0 {
log.Fatal("Session ID not found")
} else {
log.Println("Session ID discovered: ", api.SessionID)
}
} else if v, exists := os.LookupEnv("AIRBUS_SESSION_NAME"); exists {
sessions, err := api.GetSessions()
if err != nil {