Keep dependency defaults encrypted and bound secret-service failure retries
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
# Datasource provisioning
|
||||||
|
|
||||||
|
`scripts/bootstrap.py` generates the actual HTTPS/mTLS Grafana datasource file under `secrets/grafana-provisioning/datasources/`. Compose mounts that generated file, containing CA and the Grafana client identity. It is intentionally excluded from Git and the application image. Backend URLs are https://prometheus:9443, https://loki:9443 and https://tempo:9443; hostname/CA verification stays enabled.
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
apiVersion: 1
|
|
||||||
datasources:
|
|
||||||
- name: Prometheus
|
|
||||||
uid: prometheus
|
|
||||||
type: prometheus
|
|
||||||
access: proxy
|
|
||||||
url: http://prometheus:9090
|
|
||||||
isDefault: true
|
|
||||||
editable: false
|
|
||||||
- name: Loki
|
|
||||||
uid: loki
|
|
||||||
type: loki
|
|
||||||
access: proxy
|
|
||||||
url: http://loki:3100
|
|
||||||
editable: false
|
|
||||||
jsonData:
|
|
||||||
derivedFields:
|
|
||||||
- datasourceUid: tempo
|
|
||||||
matcherRegex: '"trace_id": "([a-f0-9]{32})"'
|
|
||||||
name: TraceID
|
|
||||||
url: '$${__value.raw}'
|
|
||||||
- name: Tempo
|
|
||||||
uid: tempo
|
|
||||||
type: tempo
|
|
||||||
access: proxy
|
|
||||||
url: http://tempo:3200
|
|
||||||
editable: false
|
|
||||||
@@ -220,7 +220,7 @@ def main():
|
|||||||
+ role
|
+ role
|
||||||
+ ":"
|
+ ":"
|
||||||
+ value("cache_password" if role == "api" else "cache_" + role + "_password")
|
+ value("cache_password" if role == "api" else "cache_" + role + "_password")
|
||||||
+ "@cache:6380/0?ssl_cert_reqs=required&ssl_ca_certs=/run/tls/ca.pem&ssl_certfile=/run/tls/identity/cert.pem&ssl_keyfile=/run/tls/identity/key.pem",
|
+ "@cache:6380/0?ssl_cert_reqs=required&ssl_check_hostname=True&ssl_ca_certs=/run/tls/ca.pem&ssl_certfile=/run/tls/identity/cert.pem&ssl_keyfile=/run/tls/identity/key.pem",
|
||||||
}
|
}
|
||||||
if role in {"worker", "dispatcher"}:
|
if role in {"worker", "dispatcher"}:
|
||||||
values[role]["BROKER_URL"] = (
|
values[role]["BROKER_URL"] = (
|
||||||
@@ -228,7 +228,7 @@ def main():
|
|||||||
+ role
|
+ role
|
||||||
+ ":"
|
+ ":"
|
||||||
+ value("broker_" + role + "_password")
|
+ value("broker_" + role + "_password")
|
||||||
+ "@broker:6380/0?ssl_cert_reqs=required&ssl_ca_certs=/run/tls/ca.pem&ssl_certfile=/run/tls/identity/cert.pem&ssl_keyfile=/run/tls/identity/key.pem"
|
+ "@broker:6380/0?ssl_cert_reqs=required&ssl_check_hostname=True&ssl_ca_certs=/run/tls/ca.pem&ssl_certfile=/run/tls/identity/cert.pem&ssl_keyfile=/run/tls/identity/key.pem"
|
||||||
)
|
)
|
||||||
if role in {"api", "worker"}:
|
if role in {"api", "worker"}:
|
||||||
values[role].update(
|
values[role].update(
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ from .domain import Failure
|
|||||||
_lock = threading.Lock()
|
_lock = threading.Lock()
|
||||||
_values = {}
|
_values = {}
|
||||||
_valid_until = 0.0
|
_valid_until = 0.0
|
||||||
|
_retry_after = 0.0
|
||||||
|
|
||||||
|
|
||||||
def request(path, *, data=None, token=None):
|
def request(path, *, data=None, token=None):
|
||||||
@@ -30,12 +31,14 @@ def request(path, *, data=None, token=None):
|
|||||||
|
|
||||||
|
|
||||||
def refresh():
|
def refresh():
|
||||||
global _values, _valid_until
|
global _values, _valid_until, _retry_after
|
||||||
if not os.getenv("BAO_ROLE"):
|
if not os.getenv("BAO_ROLE"):
|
||||||
return
|
return
|
||||||
with _lock:
|
with _lock:
|
||||||
if time.monotonic() < _valid_until:
|
if time.monotonic() < _valid_until:
|
||||||
return
|
return
|
||||||
|
if time.monotonic() < _retry_after:
|
||||||
|
raise Failure(503, "Сервис секретов временно недоступен")
|
||||||
try:
|
try:
|
||||||
role = os.environ["BAO_ROLE"]
|
role = os.environ["BAO_ROLE"]
|
||||||
auth = request("auth/cert/login", data={"name": role})["auth"]
|
auth = request("auth/cert/login", data={"name": role})["auth"]
|
||||||
@@ -44,10 +47,14 @@ def refresh():
|
|||||||
]
|
]
|
||||||
# Never keep credentials usable beyond the auth token's short lease.
|
# Never keep credentials usable beyond the auth token's short lease.
|
||||||
_values = values
|
_values = values
|
||||||
|
_retry_after = 0.0
|
||||||
_valid_until = time.monotonic() + min(float(auth["lease_duration"]), 30) - 1
|
_valid_until = time.monotonic() + min(float(auth["lease_duration"]), 30) - 1
|
||||||
except (OSError, ValueError, KeyError, urllib.error.URLError):
|
except (OSError, ValueError, TypeError, KeyError, urllib.error.URLError):
|
||||||
_values = {}
|
_values = {}
|
||||||
_valid_until = 0
|
_valid_until = 0
|
||||||
|
# Bound concurrent failures: one network attempt, then a brief
|
||||||
|
# fail-closed negative cache instead of serial timeout storms.
|
||||||
|
_retry_after = time.monotonic() + 1
|
||||||
raise Failure(503, "Сервис секретов временно недоступен") from None
|
raise Failure(503, "Сервис секретов временно недоступен") from None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class ObjectStorage:
|
|||||||
prefix = "S3_ADMIN" if admin else "S3"
|
prefix = "S3_ADMIN" if admin else "S3"
|
||||||
self.client = boto3.client(
|
self.client = boto3.client(
|
||||||
"s3",
|
"s3",
|
||||||
endpoint_url=os.getenv("S3_ENDPOINT", "http://s3:8333"),
|
endpoint_url=os.getenv("S3_ENDPOINT", "https://storage:8443"),
|
||||||
aws_access_key_id=secret(prefix + "_ACCESS_KEY"),
|
aws_access_key_id=secret(prefix + "_ACCESS_KEY"),
|
||||||
aws_secret_access_key=secret(prefix + "_SECRET_KEY"),
|
aws_secret_access_key=secret(prefix + "_SECRET_KEY"),
|
||||||
region_name="us-east-1",
|
region_name="us-east-1",
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ class Telemetry:
|
|||||||
handler.setFormatter(JsonFormatter())
|
handler.setFormatter(JsonFormatter())
|
||||||
root.addHandler(handler)
|
root.addHandler(handler)
|
||||||
if self.enabled:
|
if self.enabled:
|
||||||
endpoint = os.getenv("OTEL_EXPORTER_OTLP_ENDPOINT", "http://collector:4318").rstrip("/")
|
endpoint = os.getenv("OTEL_EXPORTER_OTLP_ENDPOINT", "https://collector:4318").rstrip("/")
|
||||||
common = {"timeout": 1.0}
|
common = {"timeout": 1.0}
|
||||||
# Standard OTLP environment variables also support HTTPS/mTLS in lab7.
|
# Standard OTLP environment variables also support HTTPS/mTLS in lab7.
|
||||||
trace_provider = TracerProvider(
|
trace_provider = TracerProvider(
|
||||||
|
|||||||
Reference in New Issue
Block a user