Repository navigation
fix(docker): resolve the healthcheck port instead of passing a literal - #3687
Open
qianeric-backup wants to merge 1 commit into
Open
qianeric-backup wants to merge 1 commit into
qianeric-backup wants to merge 1 commit into
Conversation
The healthcheck was declared in JSON exec form:
CMD [ "curl", "-fS", "localhost:$UI_PORT" ]
Exec-form healthchecks do not run through a shell, and Docker does not
interpolate variables inside an argv element, so the image stored the
literal string "localhost:$UI_PORT" and curl rejected it before opening a
connection:
curl: (3) URL rejected: Port number was not a decimal number between 0 and 65535
The container therefore never reported healthy, even with BeEF listening
on the default port.
Two changes are needed, because either one alone is insufficient:
- UI_PORT and the sibling ports are now also exported as environment
variables. A build argument is not visible at run time, so a shell-form
healthcheck would otherwise expand ${UI_PORT} to an empty string.
- The healthcheck uses the shell form so that expansion happens when the
check runs, plus an explicit `|| exit 1` to keep curl's status as the
healthcheck status.
Verified with a listener on port 3000: the old command exits 3, the new one
returns the response and exits 0.
Note this keeps the existing relationship between the build arguments and
the application: BeEF reads its listen address from config.yaml, so a
non-default UI_PORT still only affects the image metadata and this check.
Aligning the two would be a separate change.
Refs beefproject#3626
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Category
Bug
Feature/Issue Description
Q: Please give a brief summary of your feature/fix
A:
The image healthcheck can never report healthy. It was declared in JSON exec form:
Exec-form healthchecks do not run through a shell, and Docker stores each argv element verbatim rather than interpolating variables inside it. The built image therefore invokes curl with the literal string
localhost:$UI_PORT, which curl rejects before it opens a connection:Q: Give a technical rundown of what you have changed (if applicable)
A:
Two changes, because either one alone leaves the check broken:
UI_PORTand the sibling ports are also exported asENVvalues. A build argument is not visible at run time, so a shell-form healthcheck would otherwise expand${UI_PORT}to an empty string and requesthttp://localhost:.|| exit 1so curl's status is still what Docker records.curlis already present in the final stage, so no package changes are needed.Test Cases
Q: Describe your test cases, what you have covered and if there are any use cases that still need addressing.
A:
Docker is not available in my environment, so I could not build the image and inspect
docker image inspect --format '{{json .Config.Healthcheck.Test}}'. Instead I verified the two command forms directly against a listener on port 3000 (python3 -m http.server 3000):curl: (3) URL rejected: Port number was not a decimal number between 0 and 65535UI_PORT=3000This covers the failure mode reported in the issue. It does not cover a build with
--build-arg UI_PORT=<other>, and that is deliberate: see the open question below.Open question for the maintainers
UI_PORTcurrently has no effect on the application. BeEF reads its listen address fromconfig.yaml(http.port, default3000), which the image ships unchanged, so--build-arg UI_PORT=4321only changesEXPOSEmetadata and this healthcheck, not what BeEF actually binds. With this PR a non-defaultUI_PORTwill now point the healthcheck at a port nothing listens on, where before the check failed for a different reason.Fixing that properly means either wiring the build argument into the generated config or documenting
UI_PORTas metadata only. Both are larger decisions than a healthcheck fix, so this PR keeps the existing relationship and only makes the check resolve its port. If you would rather have the healthcheck simply hard-code the application default until the configuration story is settled, say so and I will adjust.Fixes #3626
Wiki Page
Not applicable; the Docker workflow is unchanged apart from the healthcheck reporting correctly.