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 dns resolver for docker #435

Open
wants to merge 3 commits into
base: int
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,22 @@ func Run(ctx context.Context, configFilePath string, hostDNSServer DNSServer,
// this will cause domain, IP mapping to be cached
ipAddress, err := dnsProxy.getIPByDomain(domainName)
if err != nil {
WriteLog(fmt.Sprintf("Error resolving allowed domain %v", err))
WriteAnnotation(fmt.Sprintf("%s Reverting agent since allowed endpoint %s could not be resolved", StepSecurityAnnotationPrefix, strings.Trim(domainName, ".")))
RevertChanges(iptables, nflog, cmd, resolvdConfigPath, dockerDaemonConfigPath, dnsConfig, sudo)
return err
WriteLog(fmt.Sprintf("Error resolving allowed domain in Block mode %v", err))
WriteLog("Switching to Audit mode.")

// Change the policy to Audit
config.EgressPolicy = EgressPolicyAudit
apiclient.EgressPolicy = EgressPolicyAudit

// Reinitialize the Cache with the new Audit policy
Cache = InitCache(config.EgressPolicy)

// Update DNSProxy with the new cache and EgressPolicy
dnsProxy.Cache = &Cache
dnsProxy.EgressPolicy = EgressPolicyAudit

// Exit the loop as we have switched to Audit policy
break
}
for _, endpoint := range endpoints {
// create list of ip address to be added to firewall
Expand Down
4 changes: 2 additions & 2 deletions dnsconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
// https://unix.stackexchange.com/questions/508397/what-is-the-recommended-way-to-set-a-global-dns-server-override-on-a-system-usin
// Domains=~. instructs systemd-resolved to always use the global nameservers
// and to never query any DHCP-supplied nameservers
localDnsServer = "[Resolve]\nDNS=127.0.0.1\nDomains=~.\n"
localDnsServer = "[Resolve]\nDNS=127.0.0.1 172.17.0.1\nDomains=~.\n"
)

func updateDockerConfig(configPath string) error {
Expand All @@ -46,7 +46,7 @@ func updateDockerConfig(configPath string) error {
return errors.Wrap(err, "failed to unmarshal config file")
}

m["dns"] = []string{dockerDnsServer}
// m["dns"] = []string{dockerDnsServer}
m["live-restore"] = true
// m["userns-remap"] = "runner:runner" // Checkout: https://docs.docker.com/engine/security/userns-remap/#enable-userns-remap-on-the-daemon

Expand Down
6 changes: 3 additions & 3 deletions dnsconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ func Test_updateDockerConfig(t *testing.T) {
}{
{name: "existing file",
args: args{configPath: tmpFileName},
want: "{\"cgroup-parent\":\"/actions_job\",\"dns\":[\"172.17.0.1\"],\"live-restore\":true}",
want: "{\"cgroup-parent\":\"/actions_job\",\"live-restore\":true}",
wantErr: false},
{name: "non existent file",
args: args{configPath: mockDockerConfigPath},
want: "{\"dns\":[\"172.17.0.1\"],\"live-restore\":true}",
want: "{\"live-restore\":true}",
wantErr: false},
}

Expand Down Expand Up @@ -79,7 +79,7 @@ func Test_writeResolveConfig(t *testing.T) {
}{
{name: "overwrite file",
args: args{configPath: tmpFileName},
want: "[Resolve]\nDNS=127.0.0.1\nDomains=~.\n",
want: "[Resolve]\nDNS=127.0.0.1 172.17.0.1\nDomains=~.\n",
wantErr: false},
}
for _, tt := range tests {
Expand Down
Loading