项目作者: coreos

项目描述 :
A proxy for Stripe which allows the administrator to grant permission-restricting credentials.
高级语言: Go
项目地址: git://github.com/coreos/stripe-proxy.git
创建时间: 2017-03-20T19:33:17Z
项目社区:https://github.com/coreos/stripe-proxy

开源协议:Apache License 2.0

下载


stripe-proxy

A proxy for Stripe which allows the administrator to grant permission-restricting credentials. Actual Stripe credentials are only used for signing the generated credentials, and are never shared with the end consumer. In this way the proxy can never be accidentally skipped.

Usage

There are two subcommands which can be used to interact with stripe-proxy. The sign command, which generates signed restricted credentials, and the serve command which runs the HTTP reverse proxy. All commands require the use of a stripe key with the --key parameter.

Serve

To start the reverse proxy, use a command like the following:

  1. stripe-proxy --stripekey <your_stripe_private_key> serve

Sign

To generate a set of signed credentials, you must first calculate the permissions vector as a uint32, and then pass that to the sign command. The vector is comprised of individual permissions flags corresponding to Stripe top level resources and whether you want to grant read, write, both, or none. You can run the sign command as follows:

  1. # Grants read only access to /customer/ paths
  2. stripe-proxy --stripekey <your_stripe_private_key> sign --input 64

Output:

  1. sign called with stripeKey: sk_test_redacted and input 1000000
  2. credentials: AAAAQA_<signature>

Calculation of bit offsets

The calculation for which bit corresponds to what is as follows:

Access:

  1. type Access int
  2. const (
  3. None = 0
  4. Read = 1
  5. Write = 2
  6. ReadWrite = 3
  7. )

Resources:

  1. type StripeResource int
  2. const (
  3. ResourceAll StripeResource = 0
  4. ResourceBalance = 1
  5. ResourceCharges = 2
  6. ResourceCustomers = 3
  7. ResourceDisputes = 4
  8. ResourceEvents = 5
  9. ResourceFileUploads = 6
  10. ResourceRefunds = 7
  11. ResourceTokens = 8
  12. ResourceTransfers = 9
  13. ResourceTransferReversals = 10
  14. )

Individual bit mask:

  1. func resourceMask(resource StripeResource, access Access) uint32 {
  2. return uint64(access << (uint64(resource) * 2))
  3. }

The simplest and default case of 1 corresponds to granting read only access to everything.