Skip to content
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

Fix signals and offline mode for js/wasm #683

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

hslatman
Copy link
Member

@hslatman hslatman commented Jun 2, 2022

Changes in this PR include the things I needed to change in the CLI to make it compile to js/wasm.

Had to move around and refactor some code to fix import cycles and such. I'm not completely happy with the structure yet, but it's a start.

The js/wasm build is not fully functional. There are things that are not supported in a browser environment, so these functions can't be used. Using mTLS (easily) is one of them. There are also things that aren't fully implemented yet, like the --offline mode. Currently this functionality is stubbed, so that the js/wasm build can at least compile. It would be cool to support this in the future, though, as this would allow running an offline instance of step-ca in memory in a browser.

Running GOOS=js GOARCH=wasm go build -o ./html/test.wasm -tags nobadger,nobbolt cmd/step/main.go will not result in a Wasm module yet. There are still some changes in dependencies to be completed:

# github.com/chzyer/readline
vendor/github.com/chzyer/readline/utils.go:81:29: undefined: State
vendor/github.com/chzyer/readline/utils.go:241:9: undefined: State
vendor/github.com/chzyer/readline/operation.go:234:4: undefined: ClearScreen
vendor/github.com/chzyer/readline/readline.go:129:20: undefined: GetScreenWidth
vendor/github.com/chzyer/readline/readline.go:132:22: undefined: DefaultIsTerminal
vendor/github.com/chzyer/readline/readline.go:142:26: undefined: DefaultOnWidthChanged
vendor/github.com/chzyer/readline/remote.go:324:2: undefined: DefaultOnWidthChanged
vendor/github.com/chzyer/readline/remote.go:346:17: undefined: GetScreenWidth
vendor/github.com/chzyer/readline/remote.go:362:16: undefined: DefaultIsTerminal
vendor/github.com/chzyer/readline/terminal.go:51:2: undefined: SuspendMe
vendor/github.com/chzyer/readline/terminal.go:51:2: too many errors
# github.com/newrelic/go-agent/internal/sysinfo
vendor/github.com/newrelic/go-agent/internal/sysinfo/usage_posix.go:17:17: undefined: syscall.Getrusage
vendor/github.com/newrelic/go-agent/internal/sysinfo/usage_posix.go:17:35: undefined: syscall.RUSAGE_SELF
# github.com/smallstep/zcrypto/x509
vendor/github.com/smallstep/zcrypto/x509/cert_pool.go:38:9: undefined: loadSystemRoots
vendor/github.com/smallstep/zcrypto/x509/root.go:21:32: undefined: loadSystemRoots

In my POC repo, using forks of those with dirty hacks, the Wasm compiles with the changes from this PR.

@github-actions github-actions bot added the needs triage Waiting for discussion / prioritization by team label Jun 2, 2022
@hslatman
Copy link
Member Author

hslatman commented Jun 2, 2022

There's a (recent) open PR for js/wasm target for newrelic/go-agent: newrelic/go-agent#478. That should work for us too. It's an indirect dependency through github.com/smallstep/certificates/monitoring.

We're already maintaining our own fork of github.com/smallstep/zcrypto/x509, but it's heavily outdated and it has changed a lot internally. We should be good for now to just make this build with a small patch. We can look into getting closer to upstream later. My PR to the upstream for js/wasm support was already merged: zmap/zcrypto#335.

The hardest to get working correctly is github.com/chzyer/readline. It's possible to stub out the required functions, and that's what I did in my POC, but I don't think that's acceptable to the upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Waiting for discussion / prioritization by team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant