def _validate_security_group_rule(context, rule): # TODO(mdietz): As per RM8615, Remote groups are not currently supported if rule.get("remote_group_id"): raise n_exc.InvalidInput( error_message="Remote groups are not currently supported") direction = rule.get("direction") if direction == env.Capabilities.EGRESS: if env.Capabilities.EGRESS not in CONF.QUARK.environment_capabilities: raise q_exc.EgressSecurityGroupRulesNotEnabled() protocol = rule.pop('protocol') # NOTE(roaet): these are not required by spec port_range_min = rule.get('port_range_min') port_range_max = rule.get('port_range_max') # TODO(anyone): this will error as None, so defaulting to ipv4 et = rule.get('ethertype', 'IPv4') ethertype = protocols.translate_ethertype(et) if protocol: protocol = protocols.translate_protocol(protocol, et) protocols.validate_protocol_with_port_ranges(ethertype, protocol, port_range_min, port_range_max) rule['protocol'] = protocol else: if port_range_min is not None or port_range_max is not None: raise sg_ext.SecurityGroupProtocolRequiredWithPorts() rule["ethertype"] = ethertype protocols.validate_remote_ip_prefix(ethertype, rule.get("remote_ip_prefix")) return rule
def _validate_security_group_rule(context, rule): # TODO(mdietz): As per RM8615, Remote groups are not currently supported if rule.get("remote_group_id"): raise exceptions.InvalidInput( error_message="Remote groups are not currently supported") direction = rule.get("direction") if direction == Capabilities.EGRESS: if Capabilities.EGRESS not in CONF.QUARK.environment_capabilities: raise q_exc.EgressSecurityGroupRulesNotEnabled() protocol = rule.pop('protocol') port_range_min = rule['port_range_min'] port_range_max = rule['port_range_max'] ethertype = protocols.translate_ethertype(rule["ethertype"]) if protocol: protocol = protocols.translate_protocol(protocol, rule["ethertype"]) protocols.validate_protocol_with_port_ranges(ethertype, protocol, port_range_min, port_range_max) rule['protocol'] = protocol else: if port_range_min is not None or port_range_max is not None: raise sg_ext.SecurityGroupProtocolRequiredWithPorts() rule["ethertype"] = ethertype protocols.validate_remote_ip_prefix(ethertype, rule.get("remote_ip_prefix")) return rule
def serialize_rules(self, rules): """Creates a payload for the redis server.""" # TODO(mdietz): If/when we support other rule types, this comment # will have to be revised. # Action and direction are static, for now. The implementation may # support 'deny' and 'egress' respectively in the future. We allow # the direction to be set to something else, technically, but current # plugin level call actually raises. It's supported here for unit # test purposes at this time serialized = [] for rule in rules: direction = rule["direction"] source = '' destination = '' if rule.get("remote_ip_prefix"): prefix = rule["remote_ip_prefix"] if direction == "ingress": source = self._convert_remote_network(prefix) else: if (Capabilities.EGRESS not in CONF.QUARK.environment_capabilities): raise q_exc.EgressSecurityGroupRulesNotEnabled() else: destination = self._convert_remote_network(prefix) optional_fields = {} # NOTE(mdietz): this will expand as we add more protocols protocol_map = protocols.PROTOCOL_MAP[rule["ethertype"]] if rule["protocol"] == protocol_map["icmp"]: optional_fields["icmp type"] = rule["port_range_min"] optional_fields["icmp code"] = rule["port_range_max"] else: optional_fields["port start"] = rule["port_range_min"] optional_fields["port end"] = rule["port_range_max"] payload = { "ethertype": rule["ethertype"], "protocol": rule["protocol"], "source network": source, "destination network": destination, "action": "allow", "direction": direction } payload.update(optional_fields) serialized.append(payload) return serialized