Skip to content

[codex] Add container context environment variables#569

Merged
GZTimeWalker merged 4 commits into
GZTimeWalker:workfrom
zhangpu1211:codex/container-context-env
Apr 18, 2026
Merged

[codex] Add container context environment variables#569
GZTimeWalker merged 4 commits into
GZTimeWalker:workfrom
zhangpu1211:codex/container-context-env

Conversation

@zhangpu1211

Copy link
Copy Markdown
Contributor

What changed

This PR expands the container environment metadata exposed to challenge containers for both Docker and Kubernetes providers.

It adds:

  • GZCTF_USER_ID
  • GZCTF_CHALLENGE_ID
  • GZCTF_GAME_ID for game-backed containers

The existing GZCTF_FLAG and GZCTF_TEAM_ID behavior is preserved.

Why

Today the platform already passes per-team and per-flag context into dynamic containers, but challenge images cannot reliably identify the current user, challenge, or game from environment variables alone.

Adding these official context variables makes it easier to build challenge images and helper services that need lightweight awareness of platform context without depending on provider-specific labels or external side channels.

Impact

  • Docker and Kubernetes now expose the same container context variables.
  • Exercise containers continue to omit GZCTF_GAME_ID because they are not attached to a game.
  • Admin-created test containers now also receive the game id.

Validation

  • Reviewed all ContainerConfig call sites so the new field is populated for game and admin test containers.
  • Verified the branch is pushed to zhangpu1211/GZCTF.
  • Local build validation is currently blocked because this machine only has .NET SDK 9 installed while this repo targets net10.0.

@zhangpu1211
zhangpu1211 marked this pull request as ready for review April 18, 2026 07:03
@zhangpu1211

Copy link
Copy Markdown
Contributor Author

A quick note on the latest update:

I added two follow-up commits on top of this PR:

  • Fix resource namespace and Docker env list initialization
  • Add integration tests for container context env vars

Why the non-test fix is included:

  • While validating this PR locally, the branch could not build/start correctly in integration tests because of a Program.resx resource namespace mismatch.
  • I also fixed a small List<string> initialization issue in DockerManager introduced during the env var expansion work.
  • These are the minimal fixes needed to make the branch build and to run the new tests.

Why the tests are written this way:

  • Since this PR changes the env vars injected into challenge containers, the tests verify the final env set from the active container provider.
  • The coverage includes both:
    • admin test containers
    • user dynamic challenge containers

The tests now verify:

  • GZCTF_TEAM_ID
  • GZCTF_USER_ID
  • GZCTF_CHALLENGE_ID
  • GZCTF_GAME_ID
  • GZCTF_FLAG where applicable

Local validation:

  • main project builds successfully
  • unit tests passed
  • basic integration tests passed
  • the two new container integration tests passed

If you prefer, I can also split the build/runtime fixes into a separate PR.

@codecov

codecov Bot commented Apr 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.26%. Comparing base (fb65b9b) to head (96c22a9).
⚠️ Report is 1 commits behind head on work.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             work     #569      +/-   ##
==========================================
+ Coverage   59.17%   59.26%   +0.09%     
==========================================
  Files         184      184              
  Lines        9354     9371      +17     
  Branches     1135     1137       +2     
==========================================
+ Hits         5535     5554      +19     
  Misses       3394     3394              
+ Partials      425      423       -2     
Files with missing lines Coverage Δ
src/GZCTF/Controllers/EditController.cs 50.77% <100.00%> (+0.12%) ⬆️
src/GZCTF/Models/Internal/ContainerConfig.cs 100.00% <100.00%> (ø)
src/GZCTF/Repositories/GameInstanceRepository.cs 65.91% <100.00%> (+0.12%) ⬆️
.../GZCTF/Services/Container/Manager/DockerManager.cs 53.88% <100.00%> (+2.79%) ⬆️
...TF/Services/Container/Manager/KubernetesManager.cs 70.83% <100.00%> (+1.50%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@GZTimeWalker

Copy link
Copy Markdown
Owner

Environment variables do not need to be ordered. It's fine to simply place the FLAG at the end without inserting it.

If there are concerns about memory performance, just allocate a large enough List before push.

@zhangpu1211

Copy link
Copy Markdown
Contributor Author

@GZTimeWalker Thanks, that makes sense. I simplified both providers to append GZCTF_FLAG instead of inserting it at the front, and preallocated the list capacity accordingly. This is now updated in 96c22a97.

@GZTimeWalker
GZTimeWalker changed the base branch from develop to work April 18, 2026 13:09
@GZTimeWalker
GZTimeWalker merged commit 399d546 into GZTimeWalker:work Apr 18, 2026
5 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