Skip to content

Commit

Permalink
Process dns-map entries in order
Browse files Browse the repository at this point in the history
Allows for predictable dns name mapping; most specific should appear
first in the list.
  • Loading branch information
gwatts committed May 30, 2016
1 parent 948a835 commit 8e3e130
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ ssh-key: |
* **host-sig** - The expected signature of the remote server - sshproxy will check that the signature presented by the server matches this
to prevent man-in-the-middle attacks. If it's omitted, sshproxy will prompt on first connection and then save it in the configuraiton file
* **dns-map** - A map of hostname patterns to map to an alternative IP address. The patterns may include asterisk and period operators per
the Match function documented here https://golang.org/pkg/path/#Match
the Match function documented here https://golang.org/pkg/path/#Match. Order is important as the first matching pattern is selected.
* **ssh-key** - The ssh key to use to connect to the SSH server. Must not be encrypted with a passphrase. **NOTE** Each line of the key
file must be indented.

Expand Down
19 changes: 12 additions & 7 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (

type config struct {
filename string
ProxyListen string `yaml:"proxy-listen"`
SSHHost string `yaml:"ssh-host"`
SSHUser string `yaml:"ssh-user"`
HostSig string `yaml:"host-sig,omitempty"`
DNSMap map[string]string `yaml:"dns-map"`
SSHKey string `yaml:"ssh-key"`
ProxyListen string `yaml:"proxy-listen"`
SSHHost string `yaml:"ssh-host"`
SSHUser string `yaml:"ssh-user"`
HostSig string `yaml:"host-sig,omitempty"`
DNSMap yaml.MapSlice `yaml:"dns-map"`
SSHKey string `yaml:"ssh-key"`
}

func fileExists(filename string) bool {
Expand Down Expand Up @@ -70,7 +70,12 @@ func (cfg config) save() {

func (cfg config) mapHost(name string) string {
host := strings.ToLower(name)
for k, v := range cfg.DNSMap {
for _, entry := range cfg.DNSMap {
k, kok := entry.Key.(string)
v, vok := entry.Value.(string)
if !kok || !vok {
log.Fatalf("Invalid entry in dns-map - keys and values must be strings key=%v value=%v", entry.Key, entry.Value)
}
matched, err := filepath.Match(k, host)
if err != nil {
log.Fatalf("map host error for entry=%s host=%s", k, host)
Expand Down

0 comments on commit 8e3e130

Please sign in to comment.