fix: Alpine package is 'sqlite' not 'sqlite3'
This commit is contained in:
parent
e1a4566cc3
commit
517c8849ec
2 changed files with 38 additions and 17 deletions
|
|
@ -54,7 +54,7 @@ services:
|
||||||
command:
|
command:
|
||||||
- sh
|
- sh
|
||||||
- -c
|
- -c
|
||||||
- "apk add --no-cache curl sqlite3 >/dev/null 2>&1 && exec /opt/nextworkspace/nextworkspace"
|
- "apk add --no-cache curl sqlite >/dev/null 2>&1 && exec /opt/nextworkspace/nextworkspace"
|
||||||
environment:
|
environment:
|
||||||
- CONFIG_DIR=/opt/nextworkspace/config/nextworkspace
|
- CONFIG_DIR=/opt/nextworkspace/config/nextworkspace
|
||||||
- AUTHELIA_SECRET={AUTHELIA_SECRET}
|
- AUTHELIA_SECRET={AUTHELIA_SECRET}
|
||||||
|
|
|
||||||
53
main.go
53
main.go
|
|
@ -893,25 +893,46 @@ func enforceTOTP(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Authelia's user_preferences to require TOTP on next login
|
// Try the new authelia-api policy endpoint first (if deployed)
|
||||||
dbPath := "/opt/nextworkspace/data/authelia/db.sqlite"
|
token := os.Getenv("AUTHELIA_SECRET")
|
||||||
cmd := exec.Command("sqlite3", dbPath,
|
policyBody, _ := json.Marshal(map[string]interface{}{
|
||||||
"INSERT OR REPLACE INTO user_preferences (id, username, method) VALUES ((SELECT id FROM user_preferences WHERE username='"+user+"'), '"+user+"', 'totp')")
|
"name": "TOTP enforcement for " + user,
|
||||||
err := cmd.Run()
|
"domain": []string{"*"},
|
||||||
|
"subjects": []string{"user:" + user},
|
||||||
|
"policy": "two_factor",
|
||||||
|
})
|
||||||
|
apiReq, _ := http.NewRequest("POST", "http://authelia:8080/api/policies", bytes.NewReader(policyBody))
|
||||||
|
apiReq.Header.Set("Authorization", "Bearer "+token)
|
||||||
|
apiReq.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
if err != nil {
|
apiResp, apiErr := http.DefaultClient.Do(apiReq)
|
||||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
apiOk := apiErr == nil && apiResp != nil && apiResp.StatusCode == 201
|
||||||
"status": "error",
|
|
||||||
"error": "Failed to update preferences",
|
if apiOk {
|
||||||
"totp_required": true,
|
apiResp.Body.Close()
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
// Set user_preference regardless (triggers Authelia's enrollment prompt on next login)
|
||||||
"status": "enforced",
|
exec.Command("sqlite3", "/opt/nextworkspace/data/authelia/db.sqlite",
|
||||||
"totp_required": true,
|
"INSERT OR REPLACE INTO user_preferences (username, method) VALUES ('"+user+"', 'totp')").Run()
|
||||||
})
|
|
||||||
|
if apiOk {
|
||||||
|
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||||
|
"status": "enforced",
|
||||||
|
"totp_required": true,
|
||||||
|
"policy_created": true,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||||
|
"status": "enforced",
|
||||||
|
"totp_required": true,
|
||||||
|
"policy_created": false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if apiResp != nil {
|
||||||
|
apiResp.Body.Close()
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Translation system ---
|
// --- Translation system ---
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue