Skip to content

Операторское состояние открывается и без CLOUDRU_KEY_SECRET - #710

Merged
Ageree merged 3 commits into
bro-nextfrom
claude/operator-state-key
Nov 2, 2026
Merged

Ageree merged 3 commits into
bro-nextfrom
claude/operator-state-key

Conversation

@Ageree

@Ageree Ageree commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Что меняется

host.py state save/restore больше не требует CLOUDRU_KEY_SECRET. Ключ состояния берётся по очереди: OPERATOR_STATE_KEY, прежний CLOUDRU_KEY_SECRET, S3_SECRET_ACCESS_KEY (с ним сессия и так ходит в бакет). state save запечатывает первым из заданных, state restore перебирает все, поэтому состояние, сохранённое под прежним ключом, открывается как раньше.

Компромисс

Последний вариант (ключ из S3-секрета) не даёт защиты сверх ключа бакета: у кого есть он, тот читает и шифртекст, и пароль. Прежняя схема с отдельным секретом защищала от утечки одних S3-ключей. Если нужна эта защита, достаточно задать OPERATOR_STATE_KEY.

Проверка

Проверил на настоящем openssl: старое состояние открывается ключом CLOUDRU_KEY_SECRET при любой комбинации переменных, состояние только под S3-ключом запечатывается и открывается, неверный ключ даёт понятную ошибку. Само состояние в бакете я не открывал (из облачной сессии нет доступа к bro-bucket).


Generated by Claude Code


Summary by cubic

host.py state save/restore no longer requires CLOUDRU_KEY_SECRET. The state key now comes from OPERATOR_STATE_KEY, falling back to the legacy CLOUDRU_KEY_SECRET, then S3_SECRET_ACCESS_KEY; state save seals with the first one set and state restore tries each in turn, so state saved under the old key still opens.

One caveat: the S3_SECRET_ACCESS_KEY fallback protects nothing beyond the bucket's own keys—anyone with the bucket key can already read both the ciphertext and the passphrase. Set OPERATOR_STATE_KEY if you need that separation.

Tests

  • Cover key precedence (OPERATOR_STATE_KEY > CLOUDRU_KEY_SECRET > S3_SECRET_ACCESS_KEY) and opening legacy state when a newer key is tried first.

Written for commit 681f58d. Summary will update on new commits.

View guided diff Turn on auto-fix

Ключ состояния берётся из OPERATOR_STATE_KEY, затем из прежнего
CLOUDRU_KEY_SECRET, затем из S3_SECRET_ACCESS_KEY; state restore
перебирает их, так что ранее сохранённое состояние открывается как раньше.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AXwerHR47mH3XGdoYs9NQN
@hacktron-app

hacktron-app Bot commented Nov 2, 2026

Copy link
Copy Markdown

Hacktron Security Check - Skipped

Reason: Code Review is not active for this organization

Start a free trial (no credit card required), subscribe, or add a payment method from organization billing settings

Go to: https://app.hacktron.ai/sthrip/billing

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 29c03c63-c4cc-46b8-b032-56ba51ddc021
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="scripts/cloudru-app-host/host.py">

<violation number="1" location="scripts/cloudru-app-host/host.py:1105">
P2: `state_secrets` treats a lone `S3_SECRET_ACCESS_KEY` as usable, but `s3.py` selects S3 credentials only when all four `S3_*` settings exist. With a partial S3 setup and no Cloud secret, `cmd_state` passes the guard then crashes with `KeyError`; gate this fallback on `s3.PROVIDER` or validate the complete S3 configuration.</violation>

<violation number="2" location="scripts/cloudru-app-host/host.py:1134">
P2: Changing this message leaves the existing `HostCliTest` failing: its wrong-key and tamper assertions still require `does not open with this CLOUDRU_KEY_SECRET`. Update those assertions before merging.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic


def state_secrets():
"""The secrets a sealed state may be under, the one `state save` uses first."""
names = ("OPERATOR_STATE_KEY", "CLOUDRU_KEY_SECRET", "S3_SECRET_ACCESS_KEY")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: state_secrets treats a lone S3_SECRET_ACCESS_KEY as usable, but s3.py selects S3 credentials only when all four S3_* settings exist. With a partial S3 setup and no Cloud secret, cmd_state passes the guard then crashes with KeyError; gate this fallback on s3.PROVIDER or validate the complete S3 configuration.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At scripts/cloudru-app-host/host.py, line 1105:

<comment>`state_secrets` treats a lone `S3_SECRET_ACCESS_KEY` as usable, but `s3.py` selects S3 credentials only when all four `S3_*` settings exist. With a partial S3 setup and no Cloud secret, `cmd_state` passes the guard then crashes with `KeyError`; gate this fallback on `s3.PROVIDER` or validate the complete S3 configuration.</comment>

<file context>
@@ -1097,6 +1100,12 @@ def derive(label):
 
+def state_secrets():
+    """The secrets a sealed state may be under, the one `state save` uses first."""
+    names = ("OPERATOR_STATE_KEY", "CLOUDRU_KEY_SECRET", "S3_SECRET_ACCESS_KEY")
+    return [os.environ[name] for name in names if os.environ.get(name, "").strip()]
+
</file context>
Suggested change
names = ("OPERATOR_STATE_KEY", "CLOUDRU_KEY_SECRET", "S3_SECRET_ACCESS_KEY")
names = ("OPERATOR_STATE_KEY", "CLOUDRU_KEY_SECRET")
if s3.PROVIDER:
names += ("S3_SECRET_ACCESS_KEY",)

if hmac.compare_digest(tag, hmac.new(mac_key, cipher, hashlib.sha256).digest()):
break
else:
sys.exit("the operator state does not open with OPERATOR_STATE_KEY, CLOUDRU_KEY_SECRET or S3_SECRET_ACCESS_KEY "

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Changing this message leaves the existing HostCliTest failing: its wrong-key and tamper assertions still require does not open with this CLOUDRU_KEY_SECRET. Update those assertions before merging.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At scripts/cloudru-app-host/host.py, line 1134:

<comment>Changing this message leaves the existing `HostCliTest` failing: its wrong-key and tamper assertions still require `does not open with this CLOUDRU_KEY_SECRET`. Update those assertions before merging.</comment>

<file context>
@@ -1112,13 +1121,18 @@ def seal(data, secret):
+        if hmac.compare_digest(tag, hmac.new(mac_key, cipher, hashlib.sha256).digest()):
+            break
+    else:
+        sys.exit("the operator state does not open with OPERATOR_STATE_KEY, CLOUDRU_KEY_SECRET or S3_SECRET_ACCESS_KEY "
+                 "(rotated since `state save`?)")
     read, write = os.pipe()
</file context>

@Ageree
Ageree merged commit b31659f into bro-next Nov 2, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants