Add security system #312

Closed
wants to merge 11 commits into
from

Conversation

Projects
None yet
4 participants
Contributor

zyga commented Jan 11, 2016

This branch sets the stage for pluggable security systems.

Each capability type can now refer to a list of security systems. The type can be asked to grant or revoke permission expressed by those systems. A trivial "legacy" hw-assign security system is provided.

The main intent of this branch is to discuss the interface as I have some code that uses this for apparmor and seccomp coming up.

zyga added some commits Jan 11, 2016

Bump copyright
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Add temporary Capability.{Get,Set}Attr() API to decouple from attrtypes
This patch adds a small dummy implementation for getting/setting
capability attribute. The real implementation is proposed for merging
separately.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Add capability security system interface
This patch adds an interface for security systems. Security systems are
an abstraction for configuring security associated with capabilities.
Each type will define security systems that make the permission side
of the capability work. Various security systems can be used (apparmor,
seccomp, dbus, etc.).

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Associate a list of security systems with each capability type
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Add a legacy security system
This patch adds a wrapper to use hw-access as a capability security system.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Add caps.Type.{Grant,Revoke}Permissions()
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Add a mock security system for testing
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Fix golint issues on INITIAL, GRANTED and REVOKED
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Fix golint issue on loop iteration
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
caps/security_legacy.go
+// legacySecurtySystem aids in the ongoing work to transition capability system
+// from hwaccess API to a more direct approach. It allows particular capability
+// types to define a common interface that doesn't expose hwaccess API anymore.
+type legacySecurtySystem struct {
@jdstrand

jdstrand Jan 11, 2016

Contributor

Typo: should be legacySecuritySystem

@zyga

zyga Jan 11, 2016

Contributor

Ah, great catch, corrected!

caps/types.go
@@ -83,3 +86,52 @@ func (t *Type) MarshalJSON() ([]byte, error) {
func (t *Type) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, &t.Name)
}
+
+// GrantPermissions makes it possible for the package `snapName` to use hardware
@jdstrand

jdstrand Jan 11, 2016

Contributor

'hardware' is probably not the right word here for this comment when considering pure security capabilities (eg, 'firewall-management' as opposed to 'camera')

@zyga

zyga Jan 11, 2016

Contributor

Corrected.

Contributor

jdstrand commented Jan 11, 2016

I was asked to look at the approach (ie, I haven't done an in depth code review or tested this). The direction this is going looks good from a security capabilities definition/grant/revoke perspective. Thanks!

zyga added some commits Jan 11, 2016

Fix typo in "security"
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Reword docstring for Type.GrantPermission to avoid the word hardware
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Contributor

zyga commented Jan 11, 2016

@jdstrand thanks for looking at this!

+ sec := cap.Type.SecuritySystems[j]
+ if err := sec.RevokePermissions(snapName, cap); err != nil {
+ // XXX: Should we do something other than panic here?
+ panic(fmt.Sprintf("unable to revoke partially granted permissions: %q", err))
@chipaca

chipaca Jan 12, 2016

Member

eventually yes, there's got to be a big red "give up and work out the current state of the system from the top again" button in the Overseer

+ }
+ // Grant all permissions required.
+ for i := range cap.Type.SecuritySystems {
+ sec := cap.Type.SecuritySystems[i]
@chipaca

chipaca Jan 12, 2016

Member

why not i, sec := range ...?

+}
+
+// RevokePermissions undoes the effects of GrantPermissions.
+func (t *Type) RevokePermissions(snapName string, cap *Capability) error {
@chipaca

chipaca Jan 12, 2016

Member

these two are so similar!

Member

chipaca commented Jan 12, 2016

this seems ok to me. The amount of code that's exactly line-by-line the same between Type.RevokePermissions and Type.GrantPermissions makes me think there's got to be a way of writing the code once, but it can happen later if you'd rather.

@@ -42,3 +46,22 @@ type Capability struct {
func (c Capability) String() string {
return c.Name
}
+
+// SetAttr sets capability attribute to a given value.
+// TODO: remove temporary function implementation once attrtypes are merged.
@niemeyer

niemeyer Jan 12, 2016

Contributor

Can we please drop these temporary methods altogether for the time being? They're purely a setter and a getter for a public map attribute, with literally zero benefit. That means we're simply adding cruft that needs to be removed later and that is hard to agree or disagree because the full replacement TODOs give them a blank check of existence.

+// system (syccomp, apparmor, etc) from the point of view of a capability.
+type securitySystem interface {
+ // TODO: change snap to appropriate type after current transition
+ GrantPermissions(snapName string, cap *Capability) error
@niemeyer

niemeyer Jan 12, 2016

Contributor

We agreed to not have this in our call yesterday. Every single capability type in our system will be unique, precisely because its solo purpose of existence is informing the system of a new capacity which comes along with new security behavior. We cannot hand off an arbitrary capability to a security system and expect it will know what to do with it.

+ // Fetch the attribute where the path is stored
+ path, err := cap.GetAttr(sec.AttrName)
+ if err != nil {
+ return fmt.Errorf("%s, cannot get required attribute: %q", errPrefix, err)
@niemeyer

niemeyer Jan 12, 2016

Contributor

Here the mismatch becomes obvious. How can the legacy security system know that an arbitrary capability which it has no knowledge about contains a given attribute?

Contributor

niemeyer commented Jan 12, 2016

@zyga I'm closing this for the time being. Once the points and design we discussed yesterday are addressed, please reopen it or push a new PR.

@niemeyer niemeyer closed this Jan 12, 2016

@zyga zyga deleted the zyga:add-security-system branch Mar 8, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment