Bind CMS qualification to its private registered runner identity
This commit is contained in:
@@ -43462,6 +43462,39 @@ def cms_ci_inventory_preserved(before):
|
||||
# Every preexisting container must retain its exact image and generation.
|
||||
return all(current.get(identity)==row for identity,row in before.items())
|
||||
|
||||
|
||||
def cms_ci_registered_runner_id():
|
||||
"""Bind qualification to this registered daemon, not Device Core's ID 1."""
|
||||
path = CMS_CI_ROOT / 'data' / '.runner'
|
||||
for parent in path.parents:
|
||||
if parent.is_symlink():die('CMS CI registration path contains a symlink')
|
||||
directory = path.parent.lstat()
|
||||
if (not stat.S_ISDIR(directory.st_mode) or directory.st_uid != 0
|
||||
or stat.S_IMODE(directory.st_mode) != 0o700):
|
||||
die('CMS CI registration directory must remain root-private')
|
||||
fd = os.open(str(path), os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK)
|
||||
with os.fdopen(fd, 'rb') as stream:
|
||||
info = os.fstat(stream.fileno())
|
||||
if (not stat.S_ISREG(info.st_mode) or info.st_uid != 0 or info.st_nlink != 1
|
||||
or stat.S_IMODE(info.st_mode) != 0o600 or not 1 <= info.st_size <= 16384):
|
||||
die('CMS CI registered identity metadata rejected')
|
||||
raw = stream.read(16385)
|
||||
after = os.fstat(stream.fileno())
|
||||
if (info.st_size, info.st_mtime_ns, info.st_ctime_ns) != (after.st_size, after.st_mtime_ns, after.st_ctime_ns):
|
||||
die('CMS CI registered identity changed while reading')
|
||||
try:
|
||||
value = json.loads(raw)
|
||||
identity = value.get('id')
|
||||
valid = (type(identity) is int and 0 < identity < 2**53
|
||||
and value.get('name') == 'synology-cms-build'
|
||||
and value.get('address', '').rstrip('/') == 'https://git.dcserve.ru'
|
||||
and isinstance(value.get('uuid'), str) and value['uuid']
|
||||
and isinstance(value.get('token'), str) and value['token'])
|
||||
except (ValueError, UnicodeError, AttributeError, TypeError):
|
||||
valid = False
|
||||
if not valid:die('CMS CI registered identity content rejected')
|
||||
return identity
|
||||
|
||||
# DC CMS outbound automatic deployment. All authority stays in this file.
|
||||
CMS_AUTODEPLOY_ID = 'dc-cms-autodeploy-v1-20261104-002'
|
||||
CMS_AUTODEPLOY_ENTRY = 'deployment/dc-cms-autodeploy-v1.json'
|
||||
@@ -43799,7 +43832,7 @@ def cms_autodeploy_tick():
|
||||
cms_autodeploy_root_path(path)
|
||||
queue = Queue(queue_path,first_run_number=1)
|
||||
try:
|
||||
result = Controller(queue,Source(token),CmsAutodeployInstaller()).tick()
|
||||
result = Controller(queue,Source(token,runner_id=cms_ci_registered_runner_id()),CmsAutodeployInstaller()).tick()
|
||||
except Exception as error:
|
||||
result = {'status':'attention','errorType':type(error).__name__}
|
||||
# Policy errors contain only fixed codes/IDs; other exception text
|
||||
@@ -44067,9 +44100,11 @@ def cms_autodeploy_library():
|
||||
|
||||
|
||||
class GiteaSource:
|
||||
def __init__(self, token):
|
||||
def __init__(self, token, *, runner_id=None):
|
||||
require(isinstance(token, str) and re.fullmatch(r"[0-9a-f]{40}", token), "invalid_read_token")
|
||||
require(runner_id is None or positive(runner_id), "invalid_registered_runner_id")
|
||||
self._token = token
|
||||
self._runner_id = runner_id
|
||||
self._opener = urllib.request.build_opener(urllib.request.ProxyHandler({}), NoRedirect())
|
||||
|
||||
def request(self, suffix, *, archive=False):
|
||||
@@ -44159,6 +44194,7 @@ def cms_autodeploy_library():
|
||||
return check
|
||||
|
||||
def successful_run(self, row):
|
||||
require(positive(self._runner_id), "registered_runner_identity_required")
|
||||
run = self.run(row["id"])
|
||||
require((run["run_number"], run["head_sha"], run["run_attempt"]) ==
|
||||
(row["number"], row["sha"], row["attempt"]), "qualified_run_changed")
|
||||
@@ -44170,7 +44206,8 @@ def cms_autodeploy_library():
|
||||
require(job.get("run_id") == run["id"] and job.get("head_sha") == run["head_sha"]
|
||||
and job.get("head_branch") == "master" and job.get("run_attempt") == run["run_attempt"]
|
||||
and job.get("name") == "qualify" and job.get("labels") == ["nodedc-node22-build"]
|
||||
and job.get("runner_id") == 1 and job.get("status") == "completed"
|
||||
and type(job.get("runner_id")) is int and job["runner_id"] == self._runner_id
|
||||
and job.get("runner_name") == "synology-cms-build" and job.get("status") == "completed"
|
||||
and job.get("conclusion") == "success", "qualification_job_mismatch")
|
||||
steps = job.get("steps")
|
||||
require(isinstance(steps, list) and all(isinstance(s, dict) for s in steps) and [s.get("name") for s in steps] ==
|
||||
|
||||
Reference in New Issue
Block a user