-
Notifications
You must be signed in to change notification settings - Fork 125
看板支持本地模式。支持用gitlab、github作为存储 #2251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
23065a8
feat: 支持将本地、github、gitlab作为后端存储
Micro66 cd14b14
fix(backend): encrypt project provider credentials without git iv
Micro66 fa378e8
chore(wework): log cloud project restore stages
Micro66 53aa9e3
fix(wework): restore project spaces independently
Micro66 3595380
style(wework): refine project management actions
Micro66 ab9675d
style(wework): keep project actions black when disabled
Micro66 b49a9b0
chore(wework): remove cloud project debug logs
Micro66 ee0335f
fix(wework): keep app tabs available offline
Micro66 79659ce
fix(wework): open board without cloud connection
Micro66 b99ac65
feat: 修复bug
Micro66 1139323
Merge remote-tracking branch 'github/main' into human/gazelle-2026072…
Micro66 0fb1839
test: use neutral GitLab fixture domains
Micro66 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| # SPDX-FileCopyrightText: 2026 Weibo, Inc. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Encrypted provider credentials stored with cloud project metadata.""" | ||
|
|
||
| import base64 | ||
| import hashlib | ||
| import os | ||
| from typing import Any | ||
|
|
||
| from cryptography.exceptions import InvalidTag | ||
| from cryptography.hazmat.primitives.ciphers.aead import AESGCM | ||
|
|
||
| from app.core.config import settings | ||
| from shared.utils.crypto import ( | ||
| CryptoConfigurationError, | ||
| decrypt_sensitive_data, | ||
| ) | ||
|
|
||
| TOKEN_KEY = "token" | ||
| CREDENTIAL_KEY = "credential" | ||
| CREDENTIAL_VERSION = 2 | ||
| CREDENTIAL_ALGORITHM = "aes-256-gcm" | ||
| LEGACY_CREDENTIAL_VERSION = 1 | ||
| LEGACY_CREDENTIAL_ALGORITHM = "aes-256-cbc" | ||
| NONCE_BYTES = 12 | ||
|
|
||
|
|
||
| def store_provider_config( | ||
| task_provider: str, | ||
| replacement: dict[str, object], | ||
| current: dict[str, object] | None = None, | ||
| ) -> dict[str, object]: | ||
| """Normalize provider config and encrypt a supplied token.""" | ||
| config = dict(replacement) | ||
| if CREDENTIAL_KEY in config: | ||
| raise ValueError("encrypted provider credentials cannot be supplied") | ||
| config.pop("credential_configured", None) | ||
| token_supplied = TOKEN_KEY in config | ||
| token = config.pop(TOKEN_KEY, None) | ||
| if token is not None and not isinstance(token, str): | ||
| raise ValueError("provider token must be a string") | ||
|
|
||
| if not token_supplied and current: | ||
| _preserve_credential(task_provider, current, config) | ||
| return config | ||
|
|
||
| normalized_token = token.strip() if isinstance(token, str) else "" | ||
| if normalized_token and normalized_token != "***": | ||
| config[CREDENTIAL_KEY] = _encrypt_provider_token( | ||
| normalized_token, | ||
| _credential_context(task_provider, config), | ||
| ) | ||
| return config | ||
|
|
||
|
|
||
| def mask_provider_config(provider_config: object) -> dict[str, object]: | ||
| """Return non-sensitive provider settings for normal project responses.""" | ||
| if not isinstance(provider_config, dict): | ||
| return {} | ||
| config = dict(provider_config) | ||
| configured = isinstance(config.get(CREDENTIAL_KEY), dict) | ||
| config.pop(TOKEN_KEY, None) | ||
| config.pop(CREDENTIAL_KEY, None) | ||
| config["credential_configured"] = configured | ||
| return config | ||
|
|
||
|
|
||
| def decrypt_provider_token(task_provider: str, provider_config: object) -> str | None: | ||
| """Decrypt a stored cloud project provider token.""" | ||
| if not isinstance(provider_config, dict): | ||
| return None | ||
| credential = provider_config.get(CREDENTIAL_KEY) | ||
| if not isinstance(credential, dict): | ||
| return None | ||
| version = credential.get("version") | ||
| algorithm = credential.get("algorithm") | ||
| if ( | ||
| version == LEGACY_CREDENTIAL_VERSION | ||
| and algorithm == LEGACY_CREDENTIAL_ALGORITHM | ||
| ): | ||
| return _decrypt_legacy_provider_token(credential) | ||
| if version != CREDENTIAL_VERSION or algorithm != CREDENTIAL_ALGORITHM: | ||
| raise ValueError("unsupported provider credential format") | ||
| nonce = credential.get("nonce") | ||
| ciphertext = credential.get("ciphertext") | ||
| context = credential.get("context") | ||
| expected_context = _credential_context(task_provider, provider_config) | ||
| if not isinstance(nonce, str) or not nonce: | ||
| raise ValueError("provider credential nonce is required") | ||
| if not isinstance(ciphertext, str) or not ciphertext: | ||
| raise ValueError("provider credential ciphertext is required") | ||
| if not isinstance(context, str) or context != expected_context: | ||
| raise ValueError("provider credential context does not match project") | ||
| try: | ||
| token = AESGCM(_provider_credential_key()).decrypt( | ||
| base64.b64decode(nonce, validate=True), | ||
| base64.b64decode(ciphertext, validate=True), | ||
| context.encode("utf-8"), | ||
| ) | ||
| except (InvalidTag, ValueError) as exc: | ||
| raise ValueError("provider credential decryption failed") from exc | ||
| if not token: | ||
| raise ValueError("provider credential decryption failed") | ||
| return token.decode("utf-8") | ||
|
|
||
|
|
||
| def _preserve_credential( | ||
| task_provider: str, | ||
| current: dict[str, object], | ||
| replacement: dict[str, object], | ||
| ) -> None: | ||
| credential = current.get(CREDENTIAL_KEY) | ||
| if not isinstance(credential, dict): | ||
| return | ||
| if _credential_context(task_provider, current) != _credential_context( | ||
| task_provider, replacement | ||
| ): | ||
| raise ValueError("provider token is required when repository or domain changes") | ||
| replacement[CREDENTIAL_KEY] = credential | ||
|
|
||
|
|
||
| def _credential_context(task_provider: str, config: dict[str, Any]) -> str: | ||
| repository = str(config.get("repository") or "").strip() | ||
| default_domain = "github.com" if task_provider == "github" else "gitlab.com" | ||
| domain = str(config.get("domain") or default_domain).strip() | ||
| return f"{task_provider}:{domain}:{repository}" | ||
|
|
||
|
|
||
| def _provider_credential_key() -> bytes: | ||
| material = f"wegent-cloud-project-provider:{settings.SECRET_KEY}".encode("utf-8") | ||
| return hashlib.sha256(material).digest() | ||
|
|
||
|
|
||
| def _encrypt_provider_token(token: str, context: str) -> dict[str, object]: | ||
| nonce = os.urandom(NONCE_BYTES) | ||
| ciphertext = AESGCM(_provider_credential_key()).encrypt( | ||
| nonce, | ||
| token.encode("utf-8"), | ||
| context.encode("utf-8"), | ||
| ) | ||
| return { | ||
| "version": CREDENTIAL_VERSION, | ||
| "algorithm": CREDENTIAL_ALGORITHM, | ||
| "context": context, | ||
| "nonce": base64.b64encode(nonce).decode("ascii"), | ||
| "ciphertext": base64.b64encode(ciphertext).decode("ascii"), | ||
| } | ||
|
|
||
|
|
||
| def _decrypt_legacy_provider_token(credential: dict[str, object]) -> str: | ||
| ciphertext = credential.get("ciphertext") | ||
| if not isinstance(ciphertext, str) or not ciphertext: | ||
| raise ValueError("provider credential ciphertext is required") | ||
| try: | ||
| token = decrypt_sensitive_data(ciphertext) | ||
| except CryptoConfigurationError as exc: | ||
| raise ValueError( | ||
| "legacy provider credentials require GIT_TOKEN_AES_KEY and " | ||
| "GIT_TOKEN_AES_IV" | ||
| ) from exc | ||
| if not token or token == ciphertext: | ||
| raise ValueError("provider credential decryption failed") | ||
| return token | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Masked/empty token wipes the stored credential.
token_suppliedshort-circuits the preserve path, so an update that echoes the masked placeholder ("token": "***") or an empty string drops the existingcredentialfrom the config entirely — the project silently loses its provider credential. Sincemask_provider_configis what clients read back, echoing***is a realistic client behavior (the!= "***"check acknowledges it).🐛 Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 Ruff (0.15.21)
[error] 50-50: Possible hardcoded password assigned to: "normalized_token"
(S105)
🤖 Prompt for AI Agents