[ 
https://issues.apache.org/jira/browse/KNOX-2631?focusedWorklogId=634738&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-634738
 ]

ASF GitHub Bot logged work on KNOX-2631:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 05/Aug/21 18:56
            Start Date: 05/Aug/21 18:56
    Worklog Time Spent: 10m 
      Work Description: 336699github commented on a change in pull request #477:
URL: https://github.com/apache/knox/pull/477#discussion_r683710398



##########
File path: 
gateway-server/src/main/java/org/apache/knox/gateway/webshell/JSchConnectInfo.java
##########
@@ -0,0 +1,102 @@
+/*
+ * 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 org.apache.knox.gateway.webshell;
+
+import com.jcraft.jsch.Channel;
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.JSchException;
+import com.jcraft.jsch.Session;
+import org.eclipse.jetty.io.RuntimeIOException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import java.util.Properties;
+
+/**
+ * data structure to store a connection session
+ */
+public class JSchConnectInfo extends ConnectInfo {
+
+    private JSch jsch;
+    private Channel channel;
+    private Session jschSession;
+    private static final Logger LOG = 
LoggerFactory.getLogger(JSchConnectInfo.class);
+    public JSchConnectInfo(){
+        try {
+            jsch = new JSch();
+            Properties config = new Properties();
+            config.put("StrictHostKeyChecking", "no");
+            jschSession = jsch.getSession("knoxui", "localhost", 22);
+            jschSession.setConfig(config);
+            jschSession.setPassword("knoxui");
+        }catch (JSchException e){
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public void connect(String username){
+        try {
+            jschSession.connect(30000);
+            channel = jschSession.openChannel("shell");
+            inputStream = channel.getInputStream();
+            outputStream = channel.getOutputStream();
+            channel.connect(30000);
+            String sudoCmd = "exec sudo -u "+ username + " -H bash -i\ncd 
$HOME\nwhoami\n";

Review comment:
       say the process is running as `knox`
   we should preconfigure(as root) `/etc/sudoers.d/knox` to say 
   `knox <host-name>=(*:<group-name>) NOPASSWD: /usr/bin/bash `
   which means allowing `knox` to run `bash` on `<host-name>` as any user in` 
<group-name>` without needing password. 
   or it could indicate specific usernames like 
   `knox <host-name>=(sam:sam's group) NOPASSWD: /usr/bin/bash`
   this would limit knox to ONLY run those commands as root. anything else wont 
be allowed and will be reported 
   for extra safety, i think we could also add `knox ALL=(ALL) !ALL` at the top 
of the file, which disallows knox to run all commands as root first, then 
allowing only the desired commands. 
   here is the reference: https://www.sudo.ws/man/1.8.15/sudoers.man.html 
   let me know what you think :D 
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@knox.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 634738)
    Time Spent: 1h 50m  (was: 1h 40m)

> KnoxSSO for Secure Shell Access
> -------------------------------
>
>                 Key: KNOX-2631
>                 URL: https://issues.apache.org/jira/browse/KNOX-2631
>             Project: Apache Knox
>          Issue Type: New Feature
>          Components: Homepage, KnoxSSO
>    Affects Versions: 1.5.0
>            Reporter: Lu Liu
>            Priority: Minor
>             Fix For: 1.6.0
>
>          Time Spent: 1h 50m
>  Remaining Estimate: 0h
>
> While Apache Knox aids in helping to lessen the need to gain physical access
> to deployment machines, there are still numerous compelling reasons for users
> to require such access:
> 1. Debugging, log access, etc
> 2. CLI use and automation
> 3. beeline and other clients that are deployed to gateway machines
> Gaining access to a shell for these purposes currently requires the user to 
> have
> an ssh client installed and valid credentials that can be used for ssh, such 
> as:
> username and password or SSH keys. Separate management of credentials for this
> access introduces some additional complexities which may even violate 
> enterprise
> infosec policies and require the secure distribution and management of keys.
> The intent of this proposed improvement is to add a browser based terminal 
> application
> that will provide secure access to a shell on the Knox machine. Just as any 
> resource
> exposed by or hosted by Knox, you would be able to protect access to this 
> terminal
> with any of the available security providers. We would also like to make this
> available out of the box as available from the Knox Homepage. This would make 
> the
> terminal/shell available via KnoxSSO thus providing shell access with your 
> existing
> enterprise credential authenticated SSO session.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to