Compare commits

...

1 Commits

Author SHA1 Message Date
Andrey Antukh
8c0d29bb79 Add minor compatibility adjustments for audit archive task 2026-02-27 11:50:52 +01:00
8 changed files with 48 additions and 52 deletions

2
.gitignore vendored
View File

@@ -69,7 +69,7 @@
/frontend/test-results/ /frontend/test-results/
/other/ /other/
/scripts/ /scripts/
/telemetry/ /nexus/
/tmp/ /tmp/
/vendor/**/target /vendor/**/target
/vendor/svgclean/bundle*.js /vendor/svgclean/bundle*.js

View File

@@ -2,6 +2,7 @@
export PENPOT_NITRATE_SHARED_KEY=super-secret-nitrate-api-key export PENPOT_NITRATE_SHARED_KEY=super-secret-nitrate-api-key
export PENPOT_EXPORTER_SHARED_KEY=super-secret-exporter-api-key export PENPOT_EXPORTER_SHARED_KEY=super-secret-exporter-api-key
export PENPOT_NEXUS_SHARED_KEY=super-secret-nexus-api-key
export PENPOT_SECRET_KEY=super-secret-devenv-key export PENPOT_SECRET_KEY=super-secret-devenv-key
# DEPRECATED: only used for subscriptions # DEPRECATED: only used for subscriptions

View File

@@ -103,6 +103,7 @@
[:exporter-shared-key {:optional true} :string] [:exporter-shared-key {:optional true} :string]
[:nitrate-shared-key {:optional true} :string] [:nitrate-shared-key {:optional true} :string]
[:nexus-shared-key {:optional true} :string]
[:management-api-key {:optional true} :string] [:management-api-key {:optional true} :string]
[:telemetry-uri {:optional true} :string] [:telemetry-uri {:optional true} :string]

View File

@@ -120,7 +120,7 @@
;; an external storage and data cleared. ;; an external storage and data cleared.
(def ^:private schema:event (def ^:private schema:event
[:map {:title "event"} [:map {:title "AuditEvent"}
[::type ::sm/text] [::type ::sm/text]
[::name ::sm/text] [::name ::sm/text]
[::profile-id ::sm/uuid] [::profile-id ::sm/uuid]

View File

@@ -10,14 +10,11 @@
[app.common.logging :as l] [app.common.logging :as l]
[app.common.schema :as sm] [app.common.schema :as sm]
[app.common.transit :as t] [app.common.transit :as t]
[app.common.uuid :as uuid]
[app.config :as cf] [app.config :as cf]
[app.db :as db] [app.db :as db]
[app.http.client :as http] [app.http.client :as http]
[app.setup :as-alias setup] [app.setup :as-alias setup]
[app.tokens :as tokens]
[integrant.core :as ig] [integrant.core :as ig]
[lambdaisland.uri :as u]
[promesa.exec :as px])) [promesa.exec :as px]))
;; This is a task responsible to send the accumulated events to ;; This is a task responsible to send the accumulated events to
@@ -52,19 +49,18 @@
(defn- send! (defn- send!
[{:keys [::uri] :as cfg} events] [{:keys [::uri] :as cfg} events]
(let [token (tokens/generate cfg (let [skey (-> cfg ::setup/shared-keys :nexus)
{:iss "authentication"
:uid uuid/zero})
body (t/encode {:events events}) body (t/encode {:events events})
headers {"content-type" "application/transit+json" headers {"content-type" "application/transit+json"
"origin" (str (cf/get :public-uri)) "origin" (str (cf/get :public-uri))
"cookie" (u/map->query-string {:auth-token token})} "x-shared-key" (str "nexus " skey)}
params {:uri uri params {:uri uri
:timeout 12000 :timeout 12000
:method :post :method :post
:headers headers :headers headers
:body body} :body body}
resp (http/req! cfg params)] resp (http/req! cfg params)]
(if (= (:status resp) 204) (if (= (:status resp) 204)
true true
(do (do
@@ -109,7 +105,7 @@
(def ^:private schema:handler-params (def ^:private schema:handler-params
[:map [:map
::db/pool ::db/pool
::setup/props ::setup/shared-keys
::http/client]) ::http/client])
(defmethod ig/assert-key ::handler (defmethod ig/assert-key ::handler

View File

@@ -466,16 +466,17 @@
::setup/shared-keys ::setup/shared-keys
{::setup/props (ig/ref ::setup/props) {::setup/props (ig/ref ::setup/props)
:nitrate (cf/get :nitrate-shared-key) :nexus (cf/get :nexus-shared-key)
:exporter (cf/get :exporter-shared-key)} :nitrate (cf/get :nitrate-shared-key)
:exporter (cf/get :exporter-shared-key)}
::setup/clock ::setup/clock
{} {}
:app.loggers.audit.archive-task/handler :app.loggers.audit.archive-task/handler
{::setup/props (ig/ref ::setup/props) {::setup/shared-keys (ig/ref ::setup/shared-keys)
::db/pool (ig/ref ::db/pool) ::http.client/client (ig/ref ::http.client/client)
::http.client/client (ig/ref ::http.client/client)} ::db/pool (ig/ref ::db/pool)}
:app.loggers.audit.gc-task/handler :app.loggers.audit.gc-task/handler
{::db/pool (ig/ref ::db/pool)} {::db/pool (ig/ref ::db/pool)}

View File

@@ -82,45 +82,37 @@
(db/tx-run! cfg (fn [{:keys [::db/conn]}] (db/tx-run! cfg (fn [{:keys [::db/conn]}]
(db/xact-lock! conn 0) (db/xact-lock! conn 0)
(when-not key (when-not key
(l/warn :hint (str "using autogenerated secret-key, it will change on each restart and will invalidate " (l/wrn :hint (str "using autogenerated secret-key, it will change "
"all sessions on each restart, it is highly recommended setting up the " "on each restart and will invalidate "
"PENPOT_SECRET_KEY environment variable"))) "all sessions on each restart, it is highly "
"recommended setting up the "
"PENPOT_SECRET_KEY environment variable")))
(let [secret (or key (generate-random-key))] (let [secret (or key (generate-random-key))]
(-> (get-all-props conn) (-> (get-all-props conn)
(assoc :secret-key secret) (assoc :secret-key secret)
(assoc :tokens-key (keys/derive secret :salt "tokens")) (assoc :tokens-key (keys/derive secret :salt "tokens"))
(update :instance-id handle-instance-id conn (db/read-only? pool))))))) (update :instance-id handle-instance-id conn (db/read-only? pool)))))))
(sm/register! ::props [:map-of :keyword ::sm/any])
(defmethod ig/init-key ::shared-keys (defmethod ig/init-key ::shared-keys
[_ {:keys [::props] :as cfg}] [_ {:keys [::props] :as cfg}]
(let [secret (get props :secret-key)] (let [secret (get props :secret-key)]
(d/without-nils (reduce (fn [keys id]
{:exporter (let [key (or (get cfg id)
(let [key (or (get cfg :exporter) (-> (keys/derive secret :salt (name id))
(-> (keys/derive secret :salt "exporter") (bc/bytes->b64-str true)))]
(bc/bytes->b64-str true)))] (if (or (str/empty? key)
(if (or (str/empty? key) (str/blank? key))
(str/blank? key)) (do
(do (l/wrn :id (name id) :hint "key is disabled because empty string found")
(l/wrn :hint "exporter key is disabled because empty string found") keys)
nil) (do
(do (l/inf :id (name id) :hint "key initialized" :key (d/obfuscate-string key))
(l/inf :hint "exporter key initialized" :key (d/obfuscate-string key)) (assoc keys id key)))))
key))) {}
[:exporter
:nitrate
:nexus])))
:nitrate (sm/register! ::props [:map-of :keyword ::sm/any])
(let [key (or (get cfg :nitrate) (sm/register! ::shared-keys [:map-of :keyword ::sm/text])
(-> (keys/derive secret :salt "nitrate")
(bc/bytes->b64-str true)))]
(if (or (str/empty? key)
(str/blank? key))
(do
(l/wrn :hint "nitrate key is disabled because empty string found")
nil)
(do
(l/inf :hint "nitrate key initialized" :key (d/obfuscate-string key))
key)))})))

View File

@@ -5,7 +5,7 @@
;; Copyright (c) KALEIDOS INC ;; Copyright (c) KALEIDOS INC
(ns app.common.schema (ns app.common.schema
(:refer-clojure :exclude [deref merge parse-uuid parse-long parse-double parse-boolean type keys]) (:refer-clojure :exclude [deref merge parse-uuid parse-long parse-double parse-boolean type keys select-keys])
#?(:cljs (:require-macros [app.common.schema :refer [ignoring]])) #?(:cljs (:require-macros [app.common.schema :refer [ignoring]]))
(:require (:require
#?(:clj [malli.dev.pretty :as mdp]) #?(:clj [malli.dev.pretty :as mdp])
@@ -93,6 +93,11 @@
[& items] [& items]
(apply mu/merge (map schema items))) (apply mu/merge (map schema items)))
(defn select-keys
[s keys & {:as opts}]
(let [s (schema s)]
(mu/select-keys s keys opts)))
(defn assoc-key (defn assoc-key
"Add a key & value to a schema of type [:map]. If the first level node of the schema "Add a key & value to a schema of type [:map]. If the first level node of the schema
is not a map, will do a depth search to find the first map node and add the key there." is not a map, will do a depth search to find the first map node and add the key there."
@@ -138,10 +143,10 @@
(mu/optional-keys schema keys default-options))) (mu/optional-keys schema keys default-options)))
(defn required-keys (defn required-keys
([schema] ([s]
(mu/required-keys schema nil default-options)) (mu/required-keys (schema s) nil default-options))
([schema keys] ([s keys]
(mu/required-keys schema keys default-options))) (mu/required-keys (schema s) keys default-options)))
(defn transformer (defn transformer
[& transformers] [& transformers]
@@ -646,7 +651,7 @@
{:title "set" {:title "set"
:description "Set of Strings" :description "Set of Strings"
:error/message "should be a set of strings" :error/message "should be a set of strings"
:gen/gen (-> kind sg/generator sg/set) :gen/gen (sg/mcat (fn [_] (sg/generator kind)) sg/int)
:decode/string decode :decode/string decode
:decode/json decode :decode/json decode
:encode/string encode-string :encode/string encode-string