Skip to content

chore(restrictednet): add internal/restrictednet package#3361

Open
qdm12 wants to merge 20 commits into
masterfrom
restrictednet
Open

chore(restrictednet): add internal/restrictednet package#3361
qdm12 wants to merge 20 commits into
masterfrom
restrictednet

Conversation

@qdm12

@qdm12 qdm12 commented Jun 5, 2026

Copy link
Copy Markdown
Member

See #3358

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces a new internal/restrictednet package intended to perform DNS-over-HTTPS name resolution and HTTPS requests while temporarily opening highly-restrictive outbound firewall rules (scoped by source IP/port and destination IP/port), supporting the “restricted internet when VPN tunnel is down” workflow referenced in #3358.

Changes:

  • Add internal/restrictednet client APIs for DoH-based name resolution and for opening temporary HTTPS egress rules.
  • Extend the firewall abstraction and iptables implementation with AcceptOutputFromIPPortToIPPort.
  • Add unit tests and mock generation for the new package, plus update agent guidance in AGENTS.md.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
internal/restrictednet/client.go Adds Client constructor and OpenHTTPSByDomain helper wiring DoH resolution to HTTPS rule opening.
internal/restrictednet/https.go Implements HTTPS client creation with bound dialing and temporary firewall rule add/remove.
internal/restrictednet/resolve.go Implements DoH POST queries and parsing DNS answers into netip.Addr results.
internal/restrictednet/client_test.go Adds unit test coverage for OpenHTTPS firewall rule add/remove behavior.
internal/restrictednet/resolve_test.go Adds unit test coverage for parsing DNS answers into netip.Addr.
internal/restrictednet/interfaces.go Defines the Firewall interface used by restrictednet.
internal/restrictednet/mocks_generate_test.go Adds go:generate directive for GoMock generation.
internal/restrictednet/mocks_test.go Adds generated GoMock for the restrictednet Firewall interface.
internal/firewall/wrappers.go Exposes a new wrapper method on firewall.Config.
internal/firewall/interfaces.go Extends the internal firewall implementation interface with the new accept rule method.
internal/firewall/iptables/iptables.go Adds iptables/ip6tables rule generation for source+dest IP/port-specific output acceptance.
AGENTS.md Updates repository agent/coding guidance with additional preferences.
Files not reviewed (1)
  • internal/restrictednet/mocks_test.go: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/firewall/iptables/iptables.go Outdated
Comment thread internal/restrictednet/https.go Outdated
Comment thread internal/restrictednet/https.go Outdated
Comment thread internal/restrictednet/resolve.go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 14 changed files in this pull request and generated 4 comments.

Files not reviewed (1)
  • internal/restrictednet/mocks_test.go: Language not supported

Comment thread internal/restrictednet/https.go Outdated
Comment thread internal/restrictednet/https_test.go Outdated
Comment thread internal/firewall/iptables/iptables.go
Comment thread internal/restrictednet/windows.go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 14 changed files in this pull request and generated 7 comments.

Files not reviewed (1)
  • internal/restrictednet/mocks_test.go: Language not supported

Comment thread internal/restrictednet/https.go Outdated
Comment thread internal/restrictednet/https.go Outdated
Comment thread internal/restrictednet/https.go Outdated
Comment thread internal/restrictednet/client.go Outdated
Comment thread internal/restrictednet/windows.go
Comment thread internal/restrictednet/resolve.go Outdated
Comment thread internal/firewall/iptables/iptables.go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 16 changed files in this pull request and generated 5 comments.

Files not reviewed (1)
  • internal/restrictednet/mocks_test.go: Language not supported

Comment thread internal/restrictednet/unix.go Outdated
Comment thread internal/restrictednet/resolve.go
Comment thread internal/restrictednet/https_integration_test.go
Comment thread internal/restrictednet/resolve_integration_test.go
Comment thread internal/restrictednet/client.go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 18 changed files in this pull request and generated 4 comments.

Files not reviewed (1)
  • internal/restrictednet/mocks_test.go: Language not supported

Comment thread .github/workflows/ci.yml Outdated
Comment thread internal/restrictednet/client.go
Comment thread internal/restrictednet/resolve.go
Comment thread internal/restrictednet/https.go
@qdm12 qdm12 requested a review from Copilot June 11, 2026 01:18
@qdm12 qdm12 marked this pull request as ready for review June 11, 2026 01:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 18 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • internal/restrictednet/mocks_test.go: Language not supported

Comment thread internal/restrictednet/https_integration_test.go
Comment thread internal/restrictednet/https.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 18 changed files in this pull request and generated 3 comments.

Files not reviewed (1)
  • internal/restrictednet/mocks_test.go: Language not supported

Comment thread internal/restrictednet/unix.go
Comment thread internal/restrictednet/unix.go
Comment thread internal/restrictednet/unix.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 17 changed files in this pull request and generated 8 comments.

Files not reviewed (1)
  • internal/restrictednet/mocks_test.go: Language not supported

Comment on lines +195 to +198
if message.Attributes.Src.To4() == nil {
return netip.AddrFrom16([16]byte(message.Attributes.Src)), nil
}
return netip.AddrFrom4([4]byte(message.Attributes.Src)), nil
Comment on lines +139 to +142
response, err := httpClient.Do(request)
if err != nil {
return nil, err
}
Comment on lines +51 to +58
bitsIndex := fd / 64 //nolint:mnd
if bitsIndex >= len(unix.FdSet{}.Bits) {
return fmt.Errorf("fd %d exceeds unix.Select FdSet capacity", fd)
}
wset := &unix.FdSet{}
wset.Bits[bitsIndex] |= 1 << (uint64(fd) % 64) //nolint:gosec,mnd
eset := &unix.FdSet{}
eset.Bits[bitsIndex] |= 1 << (uint64(fd) % 64) //nolint:gosec,mnd
Comment on lines +153 to +157
file := os.NewFile(uintptr(fd), "")
if file == nil {
closeFD(fd)
return nil, fmt.Errorf("creating socket file")
}
"net/netip"
"testing"

"github.com/golang/mock/gomock"
Comment on lines +10 to +12
func closeFD(fd int) {
panic("not implemented")
}
Comment thread .github/workflows/ci.yml
Comment on lines +70 to +72
- name: Run integration tests in test container
run: |
docker run --rm --entrypoint go test-container test -tags=integration ./internal/restrictednet
Comment on lines +191 to +203
func parseDestinationPort(portStr string) (port uint16, err error) {
portUint, err := strconv.ParseUint(portStr, 10, 16)
if err != nil {
return 0, err
}

const maxPortUint = 65535
switch {
case portUint == 0:
return 0, errors.New("port cannot be 0")
case portUint > maxPortUint:
return 0, fmt.Errorf("port cannot be greater than %d", maxPortUint)
}
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