Skip to content

Add --net and the project key net for the network policy - #1098

Open
beetlebugorg wants to merge 1 commit into
mainfrom
net-policy
Open

beetlebugorg wants to merge 1 commit into
mainfrom
net-policy

Conversation

@beetlebugorg

Copy link
Copy Markdown
Owner

Summary

  • ztk --net POLICY sets the network policy of socket: loopback (the default, as before), any, or allow=LIST of hosts, address ranges, and ports (ztcl.sock.parsePolicy). A bad policy is an error that shows its text.
  • ztk run reads the key net of ztcl.project. A policy other than loopback needs the consent of the user:
    • On a terminal, ztk asks the question and runs only after y.
    • With no terminal, the user gives the same policy with --net. Without it, the run stops with status 2 and names the flag, in the form of the no-terminal message of ztcl run.
    • --net with a policy other than the key's is an error.
  • The key stays out of the payload, because runcmd.payloadOf of ztcl beta.9 refuses it ("ztcl run does not yet apply the key net"). runproject.prepare now returns the payload and the policy.
  • A bundled app keeps loopback.
  • SECURITY.md has a section on the network, and docs/cli.md has the new flag.

Fixes #758

Tests

  • zig build test passes, with a new test of netNeedsConsent and of the question text, which has no control code.
  • tests/help.sh passes.
  • By hand, on main and on this branch, with --allow socket and socket 192.0.2.1 80:
    • On main: "the network policy does not allow the host".
    • With --net allow=192.0.2.0/24:80: "connection refused", so the policy let it through.
    • For a project with net allow=192.0.2.0/24:80:
      • With no terminal: status 2 and the message.
      • With --net and the same policy: it runs.
      • --net any: an error.
      • net loopback: no question.
      • net bad: an error.
    • On a pty with net any: y runs and n stops with "not run".

Notes for ztcl

The question of ztcl run (askProject, askFirst) is private to the main.zig of ztcl, so ztk has its own short question with no "always" answer. Two requests to ztcl:

  • Export the question and its store, so that ztk run can offer "always".
  • Apply the key net in ztcl run.

A script with the capability socket could reach only loopback, and no
flag changed that. `ztk --net POLICY` now sets the network policy of
ztcl: loopback (the default), any, or allow=LIST of hosts, address
ranges, and ports.

`ztk run` reads the key net of ztcl.project. A policy other than
loopback needs the consent of the user: on a terminal, ztk asks the
question and runs only after the answer y. With no terminal, the user
gives the same policy with --net, and without it the run stops with
status 2 and names the flag. --net with another policy than the key is
an error. A bad policy is an error with its text.

SECURITY.md has a section on the network.

Fixes #758
@beetlebugorg beetlebugorg added this to the v1.0.0-beta.10 milestone Dec 4, 2026

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.

A native app reaches only loopback: no flag for the network policy

1 participant