Return-Path: X-Original-To: apmail-brooklyn-dev-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6594417B15 for ; Wed, 15 Apr 2015 05:29:23 +0000 (UTC) Received: (qmail 28075 invoked by uid 500); 15 Apr 2015 05:29:18 -0000 Delivered-To: apmail-brooklyn-dev-archive@brooklyn.apache.org Received: (qmail 28042 invoked by uid 500); 15 Apr 2015 05:29:18 -0000 Mailing-List: contact dev-help@brooklyn.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.incubator.apache.org Delivered-To: mailing list dev@brooklyn.incubator.apache.org Received: (qmail 28023 invoked by uid 99); 15 Apr 2015 05:29:18 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Apr 2015 05:29:18 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 15 Apr 2015 05:28:56 +0000 Received: (qmail 27925 invoked by uid 99); 15 Apr 2015 05:28:53 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Apr 2015 05:28:53 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 46A0EDFBC6; Wed, 15 Apr 2015 05:28:53 +0000 (UTC) From: aledsage To: dev@brooklyn.incubator.apache.org Reply-To: dev@brooklyn.incubator.apache.org References: In-Reply-To: Subject: [GitHub] incubator-brooklyn pull request: Adds CreateUserPolicy Content-Type: text/plain Message-Id: <20150415052853.46A0EDFBC6@git1-us-west.apache.org> Date: Wed, 15 Apr 2015 05:28:53 +0000 (UTC) X-Virus-Checked: Checked by ClamAV on apache.org Github user aledsage commented on a diff in the pull request: https://github.com/apache/incubator-brooklyn/pull/598#discussion_r28394230 --- Diff: locations/jclouds/src/main/java/brooklyn/policy/vmcustomization/CreateUserPolicy.java --- @@ -0,0 +1,161 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package brooklyn.policy.vmcustomization; + +import java.util.List; + +import org.jclouds.compute.config.AdminAccessConfiguration; +import org.jclouds.scriptbuilder.functions.InitAdminAccess; +import org.jclouds.scriptbuilder.statements.login.AdminAccess; +import org.jclouds.scriptbuilder.statements.ssh.SshdConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import brooklyn.config.ConfigKey; +import brooklyn.entity.Entity; +import brooklyn.entity.basic.AbstractEntity; +import brooklyn.entity.basic.ConfigKeys; +import brooklyn.entity.basic.EntityInternal; +import brooklyn.entity.basic.EntityLocal; +import brooklyn.event.AttributeSensor; +import brooklyn.event.SensorEvent; +import brooklyn.event.SensorEventListener; +import brooklyn.event.basic.Sensors; +import brooklyn.location.Location; +import brooklyn.location.basic.SshMachineLocation; +import brooklyn.policy.basic.AbstractPolicy; +import brooklyn.util.flags.SetFromFlag; +import brooklyn.util.internal.ssh.SshTool; +import brooklyn.util.text.Identifiers; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +/** + * When attached to an entity, this will monitor for when an {@link SshMachineLocation} is added to that entity + * (e.g. when a VM has been provisioned for it). + * + * The policy will then (asynchronously) add a new user to the VM, with a randomly generated password. + * The ssh details will be set as a sensor on the entity. + * + * If this is used, it is strongly encouraged to tell users to change the password on first login. + * + * A preferred mechanism would be for an external key-management tool to generate ssh key-pairs for + * the user, and for the public key to be passed to Brooklyn. However, there is not a customer + * requirement for that yet, so focusing on the password-approach. + */ +public class CreateUserPolicy extends AbstractPolicy implements SensorEventListener { + + private static final Logger LOG = LoggerFactory.getLogger(CreateUserPolicy.class); + + @SetFromFlag("user") + public static final ConfigKey VM_USERNAME = ConfigKeys.newStringConfigKey("createuser.vm.user.name"); + + @SetFromFlag("grantSudo") + public static final ConfigKey GRANT_SUDO = ConfigKeys.newBooleanConfigKey( --- End diff -- Default of grantSudo=false here, so not sure we want to share with `JcloudsLocationConfig`'s (also description there says "Irrelevant if dontCreateUser is true", so wouldn't make sense in this context. This policy is not tied to VMs/clouds (it just piggie backs off the `AdminAccess` class in jclouds), so I think it would be confusing for it to reference a key in `CloudLocationConfig`. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---