Documentation ¶
Overview ¶
Package parse provides functions to parse MapR ticket strings to obtain the information contained in the ticket.
A MapR ticket is a string containing two parts, separated by a space. The first part is the cluster the ticket is for, the second part is the ticket itself. The ticket is base64 encoded and encrypted using AES-256-GCM. This package provides functions to marshal and unmarshal MapR tickets from their string representation into a struct and back.
Example ¶
This example shows a complete roundtrip of a MapR ticket. It takes a base64 encoded ticket, unmarshals it, marshals it again and prints the re-encrypted ticket. The re-encrypted ticket will be different from the original ticket even though the ticket was not changed, because the encryption uses a random nonce.
// input is a base64 encoded ticket blob := []byte(`demo.mapr.com cj1FDarNNKh7f+hL5ho1m32RzYyHPKuGIPJzE/CkUqEfcTGEP4YJuFlTsBmHuifI5 LvNob/Y4xmDsrz9OxrBnhly/0g9xAs5ApZWNY8Rcab8q70IBYIbpu7xsBBTAiVRyLJkAtGFXNn104BB0AsS55GbQFUN9NAiWL zZY3/X1ITfGfDEGaYbWWTb1LGx6C0Jjgnr7TzXv1GqwiASbcUQCXOx4inguwMneYt9KhOp89smw6GBKP064DfIMHHR6lgv0Xh BP6d9FVJ1QWKvcccvi2F3LReBtqA=`) // Parse the ticket t, err := Unmarshal(blob) if err != nil { log.Fatal(err) } // Marshal the ticket again, this will encrypt the ticket again with a random nonce, so even if // the ticket was encrypted before, it will be different now. b, err := Marshal(t) if err != nil { log.Fatal(err) } // Print the re-encrypted ticket fmt.Println(string(b))
Output:
Index ¶
Examples ¶
Constants ¶
const ErrInvalidTicket = "invalid mapr ticket"
ErrInvalidTicket is the error message returned when a ticket is invalid and cannot be parsed.
Variables ¶
This section is empty.
Functions ¶
func Equal ¶ added in v0.1.3
func Equal(x, y *MaprTicket) bool
Equal returns true if the two tickets are equal, false otherwise. This comparison is done by using the proto.Equal function provided by the protobuf library.
func Marshal ¶
func Marshal(in *MaprTicket) ([]byte, error)
Marshal takes a Ticket object and returns a byte slice containing an encoded MapR ticket string representation of the ticket as a byte slice.
Types ¶
type MaprTicket ¶
type MaprTicket struct { // the cluster the ticket is for Cluster string `json:"cluster"` // the ticket and key *mapr.TicketAndKey `json:"ticket"` }
MaprTicket is a struct representing a MapR ticket.
func NewMaprTicket ¶ added in v0.1.1
func NewMaprTicket() *MaprTicket
NewMaprTicket returns a new empty MaprTicket object, initializing fields of internal types.
func Unmarshal ¶
func Unmarshal(in []byte) (*MaprTicket, error)
Unmarshal takes a byte slice containing an encoded MapR ticket string representation of a ticket and returns a MaprTicket object.
Example ¶
This example shows how to unmarshal a MapR ticket given a base64 encoded ticket.
// input is a base64 encoded ticket blob := []byte(`demo.mapr.com cj1FDarNNKh7f+hL5ho1m32RzYyHPKuGIPJzE/CkUqEfcTGEP4YJuFlTsBmHuifI5 LvNob/Y4xmDsrz9OxrBnhly/0g9xAs5ApZWNY8Rcab8q70IBYIbpu7xsBBTAiVRyLJkAtGFXNn104BB0AsS55GbQFUN9NAiWL zZY3/X1ITfGfDEGaYbWWTb1LGx6C0Jjgnr7TzXv1GqwiASbcUQCXOx4inguwMneYt9KhOp89smw6GBKP064DfIMHHR6lgv0Xh BP6d9FVJ1QWKvcccvi2F3LReBtqA=`) // Parse the ticket t, err := Unmarshal(blob) if err != nil { log.Fatal(err) } // Print the ticket information as formatted JSON fmt.Println(t.PrettyString())
Output: { "cluster": "demo.mapr.com", "ticket": { "expiryTime": "2019-02-19T13:13:49+01:00", "creationTimeSec": "2019-02-05T13:13:49+01:00", "maxRenewalDurationSec": "30d", "encryptedTicket": "AggBH+N6bCF5TEMUkaeHo7IHYUawyrf4ncz4JdGj7uupD5ll4vY2ddibb/4rBU1hob2aMhZIwdJakKgoBxJi4fWkyXVRCj/rihDWeBoInszw1Ni6ovwqO7Q3s8kvn7QIV+8yJlilCCNM1DZwVw==", "userKey": { "key": "KPNSEc96euKFcp5DLc0gbfuLrCDolaSFIQBJzW8YSYY=" }, "userCreds": { "uid": 5000, "gids": [ 5000, 1000 ], "userName": "mapr" }, "canUserImpersonate": true } }
func (*MaprTicket) Mask ¶
func (t *MaprTicket) Mask() *MaprTicket
Mask returns a new MaprTicket object with the properties UserKey and EncryptedTicket removed.
Example ¶
This example shows how to unmarshal a MapR ticket given a base64 encoded ticket and then remove sensitive information from the ticket, ie. the encrypted ticket and the user key.
// input is a base64 encoded ticket blob := []byte(`demo.mapr.com cj1FDarNNKh7f+hL5ho1m32RzYyHPKuGIPJzE/CkUqEfcTGEP4YJuFlTsBmHuifI5 LvNob/Y4xmDsrz9OxrBnhly/0g9xAs5ApZWNY8Rcab8q70IBYIbpu7xsBBTAiVRyLJkAtGFXNn104BB0AsS55GbQFUN9NAiWL zZY3/X1ITfGfDEGaYbWWTb1LGx6C0Jjgnr7TzXv1GqwiASbcUQCXOx4inguwMneYt9KhOp89smw6GBKP064DfIMHHR6lgv0Xh BP6d9FVJ1QWKvcccvi2F3LReBtqA=`) // Parse the ticket t, err := Unmarshal(blob) if err != nil { log.Fatal(err) } // Mask the ticket, removing sensitive information t = t.Mask() // Print the ticket information as formatted JSON fmt.Println(t.PrettyString())
Output: { "cluster": "demo.mapr.com", "ticket": { "expiryTime": "2019-02-19T13:13:49+01:00", "creationTimeSec": "2019-02-05T13:13:49+01:00", "maxRenewalDurationSec": "30d", "userCreds": { "uid": 5000, "gids": [ 5000, 1000 ], "userName": "mapr" }, "canUserImpersonate": true } }
func (*MaprTicket) PrettyString ¶ added in v0.1.3
func (t *MaprTicket) PrettyString() string
PrettyString returns a pretty-printed string representation of the ticket, converting timestamps to RFC3339 and durations to human readable format.
Example ¶
// create a new MaprTicket object with some values t := NewMaprTicket() t.Cluster = "demo.mapr.com" t.UserCreds.Uid = ptr.To[uint32](1000) t.UserCreds.UserName = ptr.To[string]("mapr") t.CreationTimeSec = ptr.To[uint64](1549385629) // 2019-02-05T17:53:49+01:00 t.ExpiryTime = ptr.To[uint64](1549576429) // 2019-02-07T22:53:49+01:00 // Print the ticket information as formatted JSON fmt.Println(t.PrettyString())
Output: { "cluster": "demo.mapr.com", "ticket": { "expiryTime": "2019-02-07T22:53:49+01:00", "creationTimeSec": "2019-02-05T17:53:49+01:00", "userKey": {}, "userCreds": { "uid": 1000, "userName": "mapr", "capabilities": {} } } }
func (*MaprTicket) String ¶
func (t *MaprTicket) String() string
String returns a string representation of the ticket.
Example ¶
// create a new MaprTicket object with some values t := NewMaprTicket() t.Cluster = "demo.mapr.com" t.UserCreds.Uid = ptr.To[uint32](1000) t.UserCreds.UserName = ptr.To[string]("mapr") t.CreationTimeSec = ptr.To[uint64](1549385629) // 2019-02-05T17:53:49+01:00 t.ExpiryTime = ptr.To[uint64](1549576429) // 2019-02-07T22:53:49+01:00 // Print the ticket information as formatted JSON fmt.Println(t.String())
Output: {"cluster":"demo.mapr.com","ticket":{"userKey":{},"userCreds":{"uid":1000,"userName":"mapr","capabilities":{}},"expiryTime":1549576429,"creationTimeSec":1549385629}}