-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Julien Kassar
committed
May 14, 2018
1 parent
bab16bb
commit ab5eace
Showing
4 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package allow | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/docker/docker/api/types/volume" | ||
"github.com/docker/go-plugins-helpers/authorization" | ||
"github.com/juliengk/go-log" | ||
"github.com/juliengk/go-log/driver" | ||
"github.com/juliengk/go-utils" | ||
"github.com/juliengk/go-utils/json" | ||
"github.com/kassisol/hbm/docker/allow/types" | ||
policyobj "github.com/kassisol/hbm/object/policy" | ||
"github.com/kassisol/hbm/version" | ||
) | ||
|
||
func VolumeCreate(req authorization.Request, config *types.Config) *types.AllowResult { | ||
vol := &volume.VolumesCreateBody{} | ||
|
||
err := json.Decode(req.RequestBody, vol) | ||
if err != nil { | ||
return &types.AllowResult{Allow: false, Error: err.Error()} | ||
} | ||
|
||
defer utils.RecoverFunc() | ||
|
||
l, _ := log.NewDriver("standard", nil) | ||
|
||
p, err := policyobj.New("sqlite", config.AppPath) | ||
if err != nil { | ||
l.WithFields(driver.Fields{ | ||
"storagedriver": "sqlite", | ||
"logdriver": "standard", | ||
"version": version.Version, | ||
}).Fatal(err) | ||
} | ||
defer p.End() | ||
|
||
if len(vol.Driver) > 0 { | ||
if !p.Validate(config.Username, "volumedriver", vol.Driver, "") { | ||
return &types.AllowResult{Allow: false, Msg: fmt.Sprintf("Volume driver %s is not allowed", vol.Driver)} | ||
} | ||
} | ||
|
||
if len(vol.DriverOpts) > 0 { | ||
for k, v := range vol.DriverOpts { | ||
if vol.Driver == "local" && k == "type" && v == "tmpfs" { | ||
if !p.Validate(config.Username, "config", "container_create_param_tmpfs", "") { | ||
return &types.AllowResult{Allow: false, Msg: "--tmpfs param is not allowed"} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return &types.AllowResult{Allow: true} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package volumedriver | ||
|
||
import ( | ||
"github.com/kassisol/hbm/docker/resource" | ||
"github.com/kassisol/hbm/docker/resource/driver" | ||
) | ||
|
||
type Config struct{} | ||
|
||
func init() { | ||
resource.RegisterDriver("volumedriver", New) | ||
} | ||
|
||
func New() (driver.Resourcer, error) { | ||
return &Config{}, nil | ||
} | ||
|
||
func (c *Config) List() interface{} { | ||
return []string{} | ||
} | ||
|
||
func (c *Config) Valid(value string) error { | ||
return nil | ||
} | ||
|
||
func (c *Config) ValidOptions(options map[string]string) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters