Class: Vangrail::Label
- Inherits:
-
Object
- Object
- Vangrail::Label
- 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
-
#capabilities ⇒ Object
readonly
Returns the value of attribute capabilities.
-
#confidentiality ⇒ Object
readonly
Returns the value of attribute confidentiality.
-
#integrity ⇒ Object
readonly
Returns the value of attribute integrity.
-
#provenance ⇒ Object
readonly
Returns the value of attribute provenance.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(provenance:, integrity: DEFAULT_INTEGRITY, confidentiality: nil, capabilities: nil) ⇒ Label
constructor
A new instance of Label.
- #mix(other) ⇒ Object
- #privileged? ⇒ Boolean
- #tainted? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(provenance:, integrity: DEFAULT_INTEGRITY, confidentiality: nil, capabilities: nil) ⇒ Label
Returns a new instance of Label.
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
#capabilities ⇒ Object (readonly)
Returns the value of attribute capabilities.
122 123 124 |
# File 'lib/vangrail/origin.rb', line 122 def capabilities @capabilities end |
#confidentiality ⇒ Object (readonly)
Returns the value of attribute confidentiality.
122 123 124 |
# File 'lib/vangrail/origin.rb', line 122 def confidentiality @confidentiality end |
#integrity ⇒ Object (readonly)
Returns the value of attribute integrity.
122 123 124 |
# File 'lib/vangrail/origin.rb', line 122 def integrity @integrity end |
#provenance ⇒ Object (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 |
#hash ⇒ Object
167 168 169 |
# File 'lib/vangrail/origin.rb', line 167 def hash [self.class, provenance, integrity, confidentiality, capabilities].hash end |
#mix(other) ⇒ Object
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
139 140 141 |
# File 'lib/vangrail/origin.rb', line 139 def privileged? provenance.all?(&:privileged?) && !integrity.empty? end |
#tainted? ⇒ Boolean
143 144 145 |
# File 'lib/vangrail/origin.rb', line 143 def tainted? provenance.any?(&:untrusted?) end |
#to_h ⇒ Object
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 |