Search in sources :

Example 1 with FlushCommand

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

the class AclMaintainer method applyAcl.

private void applyAcl(ContainerName containerName, Acl acl) {
    if (isAclActive(containerName, acl)) {
        return;
    }
    final Command flush = new FlushCommand(Chain.INPUT);
    final Command rollback = new PolicyCommand(Chain.INPUT, Action.ACCEPT);
    try {
        String commands = Stream.concat(Stream.of(flush), acl.toCommands().stream()).map(command -> command.asString(IPTABLES_COMMAND)).collect(Collectors.joining("; "));
        log.debug("Running ACL command '" + commands + "' in " + containerName.asString());
        dockerOperations.executeCommandInNetworkNamespace(containerName, "/bin/sh", "-c", commands);
        containerAcls.put(containerName, acl);
    } catch (Exception e) {
        log.error("Exception occurred while configuring ACLs for " + containerName.asString() + ", attempting rollback", e);
        try {
            dockerOperations.executeCommandInNetworkNamespace(containerName, rollback.asArray(IPTABLES_COMMAND));
        } catch (Exception ne) {
            log.error("Rollback of ACLs for " + containerName.asString() + " failed, giving up", ne);
        }
    }
}
Also used : PolicyCommand(com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.PolicyCommand) ContainerName(com.yahoo.vespa.hosted.dockerapi.ContainerName) DockerOperations(com.yahoo.vespa.hosted.node.admin.docker.DockerOperations) FlushCommand(com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.FlushCommand) HashMap(java.util.HashMap) NodeRepository(com.yahoo.vespa.hosted.node.admin.configserver.noderepository.NodeRepository) Collectors(java.util.stream.Collectors) Pair(com.yahoo.collections.Pair) List(java.util.List) Stream(java.util.stream.Stream) Chain(com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.Chain) Command(com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.Command) Map(java.util.Map) ContainerAclSpec(com.yahoo.vespa.hosted.node.admin.ContainerAclSpec) Optional(java.util.Optional) Action(com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.Action) PrefixLogger(com.yahoo.vespa.hosted.node.admin.util.PrefixLogger) FlushCommand(com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.FlushCommand) PolicyCommand(com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.PolicyCommand) FlushCommand(com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.FlushCommand) Command(com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.Command) PolicyCommand(com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.PolicyCommand)

Aggregations

Pair (com.yahoo.collections.Pair)1 ContainerName (com.yahoo.vespa.hosted.dockerapi.ContainerName)1 ContainerAclSpec (com.yahoo.vespa.hosted.node.admin.ContainerAclSpec)1 NodeRepository (com.yahoo.vespa.hosted.node.admin.configserver.noderepository.NodeRepository)1 DockerOperations (com.yahoo.vespa.hosted.node.admin.docker.DockerOperations)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 FlushCommand (com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.FlushCommand)1 PolicyCommand (com.yahoo.vespa.hosted.node.admin.maintenance.acl.iptables.PolicyCommand)1 PrefixLogger (com.yahoo.vespa.hosted.node.admin.util.PrefixLogger)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1