Skip to content

feat(publisher): read the login private key from a file or MCP_PRIVATE_KEY - #1734

Open
JosephDoUrden wants to merge 1 commit into
modelcontextprotocol:mainfrom
JosephDoUrden:feat/private-key-file
Open

JosephDoUrden wants to merge 1 commit into
modelcontextprotocol:mainfrom
JosephDoUrden:feat/private-key-file

Conversation

@JosephDoUrden

Copy link
Copy Markdown
Contributor

Summary

mcp-publisher login dns and login http only take the signing key as --private-key <hex>, so it lands in the process list, shell history and CI logs. #1704 asks for a file or an env var. This adds both: --private-key-file <path> and MCP_PRIVATE_KEY, read the same way --token falls back to MCP_GITHUB_TOKEN (auth/github-at.go:134). The env var name is the one the GitHub Actions docs already use for the secret (github-actions.mdx:245,269); the issue suggested MCP_PUBLISHER_PRIVATE_KEY, easy to rename if you prefer that.

Change

resolvePrivateKey in login.go: --private-key and --private-key-file are mutually exclusive, either one overrides MCP_PRIVATE_KEY, and with nothing set the existing "private key (hex) is required" error is unchanged. The file is read with a plain os.ReadFile and trimmed, so LF and CRLF both work. A file that starts with -----BEGIN gets a clear error saying to pass the hex key, because key.pem is the file the setup steps leave behind and that is the mistake people will make. An empty file is an error rather than a silent fall-through to the env var. No stdin, no PEM parsing. The azure-key-vault and google-kms subcommands are untouched.

Docs: the dns and http examples in authentication.mdx now pass the key through the env var instead of on the command line, github-actions.mdx moves the secret under env: and off the run: line, and commands.md lists the flag and the env var and writes key.hex under umask 077.

Test

Unit tests for resolvePrivateKey cover file, env, each precedence case, both flags, missing path, directory, empty file with the env var set, CRLF, whitespace around the env value and the PEM prefix. Two black-box logins (file and env) run against an httptest /v0/auth/dns that verifies the Ed25519 signature with the generated public key and returns 401 otherwise; flipping a byte of the key makes them fail. go test ./cmd/publisher/..., go vet, gofmt and golangci-lint v2.13.1 (what CI pins) are clean. I also ran the built binary against a closed port for LF, CRLF, uppercase hex, a path with spaces, a symlink and the env route; every one reached the network step, and both-flags, missing path, directory and empty file each produced their error.

Closes #1704

AI Disclosure

AI assistance (Claude) was used for issue research and during development. All changes were reviewed and tested by the author.

…E_KEY

mcp-publisher login dns and login http only took the signing key as
--private-key <hex>, which lands in the process list, shell history and
CI logs. Add --private-key-file <path> and the MCP_PRIVATE_KEY
environment variable, resolved the same way --token falls back to
MCP_GITHUB_TOKEN: the two flags are mutually exclusive, either one
overrides the env var, and with nothing set the existing "private key
(hex) is required" error is unchanged. A PEM file gets a clear error,
an empty file is an error rather than a silent fall-through.

Docs move the key off the command line in the dns/http examples and
under env: in the GitHub Actions workflow.

Closes modelcontextprotocol#1704

This branch has not been deployed

No deployments
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.

login dns/http: accept the private key from an environment variable or a file, not only --private-key

1 participant