@@ -46,16 +46,22 @@ var _ mid.RequestInterceptor = (*PrivacyMapper)(nil)
46
46
// PrivacyMapper is a RequestInterceptor that maps any pseudo names in certain
47
47
// requests to their real values and vice versa for responses.
48
48
type PrivacyMapper struct {
49
- newDB firewalldb.NewPrivacyMapDB
50
- randIntn func (int ) (int , error )
49
+ newDB firewalldb.NewPrivacyMapDB
50
+ randIntn func (int ) (int , error )
51
+ sessionIDIndexDB session.IDToGroupIndex
51
52
}
52
53
53
54
// NewPrivacyMapper returns a new instance of PrivacyMapper. The randIntn
54
55
// function is used to draw randomness for request field obfuscation.
55
56
func NewPrivacyMapper (newDB firewalldb.NewPrivacyMapDB ,
56
- randIntn func (int ) (int , error )) * PrivacyMapper {
57
+ randIntn func (int ) (int , error ),
58
+ sessionIDIndexDB session.IDToGroupIndex ) * PrivacyMapper {
57
59
58
- return & PrivacyMapper {newDB : newDB , randIntn : randIntn }
60
+ return & PrivacyMapper {
61
+ newDB : newDB ,
62
+ randIntn : randIntn ,
63
+ sessionIDIndexDB : sessionIDIndexDB ,
64
+ }
59
65
}
60
66
61
67
// Name returns the name of the interceptor.
@@ -91,6 +97,12 @@ func (p *PrivacyMapper) Intercept(ctx context.Context,
91
97
return nil , fmt .Errorf ("could not extract ID from macaroon" )
92
98
}
93
99
100
+ // Get group ID for session ID.
101
+ groupID , err := p .sessionIDIndexDB .GetGroupID (sessionID )
102
+ if err != nil {
103
+ return nil , err
104
+ }
105
+
94
106
log .Tracef ("PrivacyMapper: Intercepting %v" , ri )
95
107
96
108
switch r := req .InterceptType .(type ) {
@@ -108,7 +120,7 @@ func (p *PrivacyMapper) Intercept(ctx context.Context,
108
120
}
109
121
110
122
replacement , err := p .checkAndReplaceIncomingRequest (
111
- ctx , r .Request .MethodFullUri , msg , sessionID ,
123
+ ctx , r .Request .MethodFullUri , msg , groupID ,
112
124
)
113
125
if err != nil {
114
126
return mid .RPCErr (req , err )
@@ -142,7 +154,7 @@ func (p *PrivacyMapper) Intercept(ctx context.Context,
142
154
}
143
155
144
156
replacement , err := p .replaceOutgoingResponse (
145
- ctx , r .Response .MethodFullUri , msg , sessionID ,
157
+ ctx , r .Response .MethodFullUri , msg , groupID ,
146
158
)
147
159
if err != nil {
148
160
return mid .RPCErr (req , err )
@@ -167,10 +179,10 @@ func (p *PrivacyMapper) Intercept(ctx context.Context,
167
179
// checkAndReplaceIncomingRequest inspects an incoming request and optionally
168
180
// modifies some of the request parameters.
169
181
func (p * PrivacyMapper ) checkAndReplaceIncomingRequest (ctx context.Context ,
170
- uri string , req proto.Message , sessionID session.ID ) (proto.Message ,
182
+ uri string , req proto.Message , groupID session.ID ) (proto.Message ,
171
183
error ) {
172
184
173
- db := p .newDB (sessionID )
185
+ db := p .newDB (groupID )
174
186
175
187
// If we don't have a handler for the URI, we don't allow the request
176
188
// to go through.
@@ -193,9 +205,9 @@ func (p *PrivacyMapper) checkAndReplaceIncomingRequest(ctx context.Context,
193
205
// replaceOutgoingResponse inspects the responses before sending them out to the
194
206
// client and replaces them if needed.
195
207
func (p * PrivacyMapper ) replaceOutgoingResponse (ctx context.Context , uri string ,
196
- resp proto.Message , sessionID session.ID ) (proto.Message , error ) {
208
+ resp proto.Message , groupID session.ID ) (proto.Message , error ) {
197
209
198
- db := p .newDB (sessionID )
210
+ db := p .newDB (groupID )
199
211
200
212
// If we don't have a handler for the URI, we don't allow the response
201
213
// to go to avoid accidental leaks.
0 commit comments