Search in sources :

Example 1 with FilterCommand

use of com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.FilterCommand in project vespa by vespa-engine.

the class Acl method toCommands.

public List<Command> toCommands() {
    final ImmutableList.Builder<Command> commands = ImmutableList.builder();
    commands.add(// Default policies. Packets that do not match any rules will be processed according to policy.
    new PolicyCommand(Chain.INPUT, Action.DROP), new PolicyCommand(Chain.FORWARD, Action.DROP), new PolicyCommand(Chain.OUTPUT, Action.ACCEPT), // Allow packets belonging to established connections
    new FilterCommand(Chain.INPUT, Action.ACCEPT).withOption("-m", "state").withOption("--state", "RELATED,ESTABLISHED"), // Allow any loopback traffic
    new FilterCommand(Chain.INPUT, Action.ACCEPT).withOption("-i", "lo"), // Allow IPv6 ICMP packets. This is required for IPv6 routing (e.g. path MTU) to work correctly.
    new FilterCommand(Chain.INPUT, Action.ACCEPT).withOption("-p", "ipv6-icmp"));
    // Allow traffic from trusted containers
    containerAclSpecs.stream().map(ContainerAclSpec::ipAddress).filter(Acl::isIpv6).map(ipAddress -> new FilterCommand(Chain.INPUT, Action.ACCEPT).withOption("-s", String.format("%s/128", ipAddress))).forEach(commands::add);
    // Reject all other packets. This means that packets that would otherwise be processed according to policy, are
    // matched by the following rule.
    // 
    // Ideally, we want to set the INPUT policy to REJECT and get rid of this rule, but unfortunately REJECT is not
    // a valid policy action.
    commands.add(new FilterCommand(Chain.INPUT, Action.REJECT));
    return commands.build();
}
Also used : Objects(java.util.Objects) Inet6Address(java.net.Inet6Address) PolicyCommand(com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.PolicyCommand) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Chain(com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.Chain) Command(com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.Command) FilterCommand(com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.FilterCommand) ContainerAclSpec(com.yahoo.vespa.hosted.node.admin.ContainerAclSpec) InetAddresses(com.google.common.net.InetAddresses) Action(com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.Action) FilterCommand(com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.FilterCommand) PolicyCommand(com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.PolicyCommand) Command(com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.Command) FilterCommand(com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.FilterCommand) ImmutableList(com.google.common.collect.ImmutableList) PolicyCommand(com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.PolicyCommand)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 InetAddresses (com.google.common.net.InetAddresses)1 ContainerAclSpec (com.yahoo.vespa.hosted.node.admin.ContainerAclSpec)1 Action (com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.Action)1 Chain (com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.Chain)1 Command (com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.Command)1 FilterCommand (com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.FilterCommand)1 PolicyCommand (com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.PolicyCommand)1 Inet6Address (java.net.Inet6Address)1 List (java.util.List)1 Objects (java.util.Objects)1