Skip to content

Commit acafc9a

Browse files
committed
move ConnectionHash into Connection
1 parent 03b6412 commit acafc9a

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

cmd/epithet/match.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func (m *MatchCLI) Run(logger *slog.Logger) error {
5151
RemoteUser: m.User,
5252
Port: m.Port,
5353
ProxyJump: m.ProxyJump,
54+
Hash: m.Hash,
5455
},
55-
ConnectionHash: m.Hash,
5656
}
5757

5858
// Call broker

pkg/broker/agent_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ func TestBroker_NoAgentReturnsNotAllowed(t *testing.T) {
4848
req := MatchRequest{
4949
Connection: policy.Connection{
5050
RemoteHost: "server.example.com",
51+
Hash: "nonexistent-hash",
5152
},
52-
ConnectionHash: "nonexistent-hash",
5353
}
5454
var resp MatchResponse
5555

pkg/broker/broker.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ func (b *Broker) startBrokerListener() error {
7575
}
7676

7777
type MatchRequest struct {
78-
Connection policy.Connection
79-
ConnectionHash string
78+
Connection policy.Connection
8079
}
8180

8281
type MatchResponse struct {
@@ -93,17 +92,17 @@ func (b *Broker) Match(input MatchRequest, output *MatchResponse) error {
9392
defer b.lock.Unlock()
9493

9594
// Check if agent already exists for this connection hash
96-
if entry, exists := b.agents[input.ConnectionHash]; exists {
95+
if entry, exists := b.agents[input.Connection.Hash]; exists {
9796
// Check if agent's certificate is still valid (with buffer)
9897
if time.Now().Add(expiryBuffer).Before(entry.expiresAt) {
99-
b.log.Debug("found existing valid agent", "hash", input.ConnectionHash, "expires", entry.expiresAt)
98+
b.log.Debug("found existing valid agent", "hash", input.Connection.Hash, "expires", entry.expiresAt)
10099
output.Allow = true
101100
return nil
102101
}
103102
// Agent expired - clean it up
104-
b.log.Debug("cleaning up expired agent", "hash", input.ConnectionHash, "expired", entry.expiresAt)
103+
b.log.Debug("cleaning up expired agent", "hash", input.Connection.Hash, "expired", entry.expiresAt)
105104
entry.agent.Close()
106-
delete(b.agents, input.ConnectionHash)
105+
delete(b.agents, input.Connection.Hash)
107106
}
108107

109108
// Check if we have an auth token, if not authenticate
@@ -126,7 +125,7 @@ func (b *Broker) Match(input MatchRequest, output *MatchResponse) error {
126125
// TODO(epithet-25): Create agent with credential
127126

128127
// For now, just return false (no agent available)
129-
b.log.Debug("no valid agent found for connection", "hash", input.ConnectionHash, "host", input.Connection.RemoteHost)
128+
b.log.Debug("no valid agent found for connection", "hash", input.Connection.Hash, "host", input.Connection.RemoteHost)
130129
output.Allow = false
131130
return nil
132131
}

pkg/broker/broker_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ printf '%s' "6:thello,"
7878
RemoteUser: "root",
7979
Port: 22,
8080
ProxyJump: "bastion.example.com",
81+
Hash: "abc123def456",
8182
},
82-
ConnectionHash: "abc123def456",
8383
}
8484

8585
resp := MatchResponse{}

pkg/policy/policy.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import "path/filepath"
55
// Connection represents the complete tuple of SSH connection parameters.
66
// This matches the parameters available in OpenSSH Match exec via %C hash:
77
// local hostname (%l), remote hostname (%h), port (%p), remote user (%r), and ProxyJump (%j).
8+
// The Hash field contains the %C hash value computed by OpenSSH from these parameters.
89
type Connection struct {
910
LocalHost string `json:"localHost"`
1011
LocalUser string `json:"localUser"`
1112
RemoteHost string `json:"remoteHost"`
1213
RemoteUser string `json:"remoteUser"`
1314
Port uint `json:"port"`
1415
ProxyJump string `json:"proxyJump"`
16+
Hash string `json:"hash"` // %C - hash of connection tuple
1517
}
1618

1719
// Policy represents the policy rules for certificate usage

0 commit comments

Comments
 (0)