Class: Vangrail::Label

Inherits:
Object
  • Object
show all
Defined in:
lib/vangrail/origin.rb

Overview

Immutable security metadata carried by a Cell.

Provenance accumulates. Integrity records the trusted principals whose values contributed to a result; an empty set cannot authorize control flow. Confidentiality is an allowlist of sinks, where nil means no sink restriction. Capability tokens are intersected, and any untrusted provenance removes them.

Constant Summary collapse

DEFAULT_INTEGRITY =
Object.new.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provenance:, integrity: DEFAULT_INTEGRITY, confidentiality: nil, capabilities: nil) ⇒ Label

Returns a new instance of Label.

Raises:

  • (ArgumentError)


124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/vangrail/origin.rb', line 124

def initialize(provenance:, integrity: DEFAULT_INTEGRITY, confidentiality: nil,
               capabilities: nil)
  @provenance = Array(provenance).map { |origin| Origin.coerce(origin) }.uniq.freeze
  raise ArgumentError, 'a label needs at least one origin' if @provenance.empty?

  @integrity = normalize(integrity.equal?(DEFAULT_INTEGRITY) ? default_integrity : integrity)
  @confidentiality = normalize_optional(confidentiality)
  @capabilities = if @provenance.any?(&:untrusted?)
                    [].freeze
                  else
                    normalize_optional(capabilities)
                  end
  freeze
end

Instance Attribute Details

#capabilitiesObject (readonly)

Returns the value of attribute capabilities.



122
123
124
# File 'lib/vangrail/origin.rb', line 122

def capabilities
  @capabilities
end

#confidentialityObject (readonly)

Returns the value of attribute confidentiality.



122
123
124
# File 'lib/vangrail/origin.rb', line 122

def confidentiality
  @confidentiality
end

#integrityObject (readonly)

Returns the value of attribute integrity.



122
123
124
# File 'lib/vangrail/origin.rb', line 122

def integrity
  @integrity
end

#provenanceObject (readonly)

Returns the value of attribute provenance.



122
123
124
# File 'lib/vangrail/origin.rb', line 122

def provenance
  @provenance
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



159
160
161
162
163
# File 'lib/vangrail/origin.rb', line 159

def ==(other)
  other.is_a?(self.class) && other.provenance == provenance &&
    other.integrity == integrity && other.confidentiality == confidentiality &&
    other.capabilities == capabilities
end

#hashObject



167
168
169
# File 'lib/vangrail/origin.rb', line 167

def hash
  [self.class, provenance, integrity, confidentiality, capabilities].hash
end

#mix(other) ⇒ Object

Raises:

  • (ArgumentError)


147
148
149
150
151
152
153
154
155
156
157
# File 'lib/vangrail/origin.rb', line 147

def mix(other)
  raise ArgumentError, 'labels can only mix with labels' unless other.is_a?(self.class)

  combined_provenance = (provenance + other.provenance).uniq
  self.class.new(
    provenance: combined_provenance,
    integrity: merge_integrity(other),
    confidentiality: restrict(confidentiality, other.confidentiality),
    capabilities: merge_capabilities(other, combined_provenance),
  )
end

#privileged?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/vangrail/origin.rb', line 139

def privileged?
  provenance.all?(&:privileged?) && !integrity.empty?
end

#tainted?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/vangrail/origin.rb', line 143

def tainted?
  provenance.any?(&:untrusted?)
end

#to_hObject



171
172
173
174
175
176
177
178
# File 'lib/vangrail/origin.rb', line 171

def to_h
  {
    'provenance' => provenance.map(&:to_s),
    'integrity' => integrity.map(&:to_s),
    'confidentiality' => confidentiality&.map(&:to_s),
    'capabilities' => capabilities&.map(&:to_s),
  }.compact
end