Skip to content

Commit 2b53958

Browse files
author
Andrew Mitchell
committed
Adds ComplianceRegion to Op protocol
1 parent 6aa62fb commit 2b53958

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

protocol/protocol.go

+46-14
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ const (
5151
TagJaegerSpan Tag = 0x15
5252
// TagReqContext contains request metadata
5353
TagReqContext Tag = 0x16
54+
// TagComplianceRegion implies the compliance region of the operation which can impact behavior
55+
TagComplianceRegion Tag = 0x17
5456
// TagPadding implies an item with a meaningless payload added for padding.
5557
TagPadding Tag = 0x20
5658
)
@@ -202,6 +204,25 @@ func (e Error) String() string {
202204
}
203205
}
204206

207+
// ComplianceRegion describes any guardrails that gokeyless should follow when accessing data from
208+
// external applications
209+
type ComplianceRegion byte
210+
211+
const (
212+
// ComplianceRegionFedRAMPHigh signals that this operation should only interact
213+
// with the FedRAMP High QS instance
214+
ComplianceRegionFedRAMPHigh ComplianceRegion = 0x01
215+
)
216+
217+
func (cr ComplianceRegion) String() string {
218+
switch cr {
219+
case ComplianceRegionFedRAMPHigh:
220+
return "fedramp_high"
221+
default:
222+
return "retail"
223+
}
224+
}
225+
205226
const (
206227
paddedLength = 1024
207228
headerSize = 8
@@ -405,30 +426,32 @@ func (p *Packet) ReadFrom(r io.Reader) (n int64, err error) {
405426

406427
// Operation defines a single (repeatable) keyless operation.
407428
type Operation struct {
408-
Opcode Op
409-
Payload []byte
410-
Extra []byte
411-
SKI SKI
412-
Digest Digest
413-
ClientIP net.IP
414-
ServerIP net.IP
415-
SNI string
416-
CertID string
417-
ForwardingSvc int64
418-
CustomFuncName string
419-
JaegerSpan []byte
420-
ReqContext []byte
429+
Opcode Op
430+
Payload []byte
431+
Extra []byte
432+
SKI SKI
433+
Digest Digest
434+
ClientIP net.IP
435+
ServerIP net.IP
436+
SNI string
437+
CertID string
438+
ForwardingSvc int64
439+
CustomFuncName string
440+
JaegerSpan []byte
441+
ReqContext []byte
442+
ComplianceRegion ComplianceRegion
421443
}
422444

423445
func (o *Operation) String() string {
424-
return fmt.Sprintf("[Opcode: %v, SKI: %v, Digest: %02x, Client IP: %s, Server IP: %s, SNI: %s, Forwarding Service: %v]",
446+
return fmt.Sprintf("[Opcode: %v, SKI: %v, Digest: %02x, Client IP: %s, Server IP: %s, SNI: %s, Forwarding Service: %v, ComplianceRegion %v]",
425447
o.Opcode,
426448
o.SKI,
427449
o.Digest,
428450
o.ClientIP,
429451
o.ServerIP,
430452
o.SNI,
431453
o.ForwardingSvc,
454+
o.ComplianceRegion,
432455
)
433456
}
434457

@@ -512,6 +535,8 @@ func (o *Operation) Bytes() uint16 {
512535
if o.ReqContext != nil {
513536
add(tlvLen(len(o.ReqContext)))
514537
}
538+
// compliance region
539+
add(tlvLen(1))
515540
if int(length)+headerSize < paddedLength {
516541
// TODO: Are we sure that's the right behavior?
517542

@@ -586,6 +611,8 @@ func (o *Operation) MarshalBinary() ([]byte, error) {
586611
b = append(b, tlvBytes(TagReqContext, o.ReqContext)...)
587612
}
588613

614+
b = append(b, tlvBytes(TagComplianceRegion, []byte{byte(o.ComplianceRegion)})...)
615+
589616
if len(b)+headerSize < paddedLength {
590617
// TODO: Are we sure that's the right behavior?
591618

@@ -673,6 +700,11 @@ func (o *Operation) UnmarshalBinary(body []byte) error {
673700
o.JaegerSpan = data
674701
case TagReqContext:
675702
o.ReqContext = data
703+
case TagComplianceRegion:
704+
if len(data) != 1 {
705+
return fmt.Errorf("invalid ComplianceRegion: %s", data)
706+
}
707+
o.ComplianceRegion = ComplianceRegion(data[0])
676708
default:
677709
// Silently ignore any unknown tags (to allow for new tags to be gradually added to the protocol).
678710
continue

protocol/protocol.md

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ The following tag values are possible for items:
3939
0x13 - CustomFuncName, (for use with opcode 0x24)
4040
0x14 - Supplemental payload, whose meaning is not specified and must be predetermined between the server and client,
4141
0x15 - Binary encoded Jaeger span (https://www.jaegertracing.io/docs/1.19/client-libraries/#value)
42+
0x17 - ComplianceRegion,
4243

4344
A requests contains a header and the following items:
4445

0 commit comments

Comments
 (0)