Compare commits

...

4 Commits

Author SHA1 Message Date
Manfred Touron
f9c8f60365 Merge pull request #465 from Doozers/fix/isma/rand-lib
fix: change rand lib(math/rand => crypto/rand)
2023-05-20 11:26:37 +02:00
Manfred Touron
db5cfec59a Merge pull request #416 from omahs/patch-1 2023-05-19 09:14:19 +02:00
ismael FALL
a30952348b fix: change rand lib(math/rand => crypto/rand)
Signed-off-by: ismael FALL <ismael.fall@epitech.eu>
2023-05-17 11:33:00 +02:00
omahs
dd4a21032f Fix: typos
Fix: typos
2022-11-01 14:23:37 +01:00
3 changed files with 25 additions and 13 deletions

View File

@@ -61,7 +61,7 @@ Shared connection to localhost closed.
$
```
If the association fails and you are promted for a password, verify that the host you're connecting from has a SSH key set up or generate one with ```ssh-keygen -t rsa```
If the association fails and you are prompted for a password, verify that the host you're connecting from has a SSH key set up or generate one with ```ssh-keygen -t rsa```
Drop an interactive administrator shell
@@ -135,7 +135,7 @@ Used by educators to provide temporary access to students. [Feedback from a teac
There are companies who use a jump host to monitor connections at a single point.
A hosting company is using SSHportal for its “logging” feature, among the others. As every session is logged and introspectable, they have a detailed history of who performed which action. This company made its own contribution on the project, allowing the support of [more than 65.000 sessions in the database](https://github.com/moul/sshportal/pull/76).
A hosting company is using SSHportal for its “logging” feature, among others. As every session is logged and introspectable, they have a detailed history of who performed which action. This company made its own contribution to the project, allowing the support of [more than 65.000 sessions in the database](https://github.com/moul/sshportal/pull/76).
The project has also received [multiple contributions from a security researcher](https://github.com/moul/sshportal/pulls?q=is%3Apr+author%3Asabban+sort%3Aupdated-desc) that made a thesis on quantum cryptography. This person uses SSHportal in their security-hardened hosting company.
@@ -155,7 +155,7 @@ If you need to invite multiple people to an event (hackathon, course, etc), the
* User management (invite, group, stats)
* Host Key management (create, remove, update, import)
* Automatic remote host key learning
* User Key management (multile keys per user)
* User Key management (multiple keys per user)
* ACL management (acl+user-groups+host-groups)
* User roles (admin, trusted, standard, ...)
* User invitations (no more "give me your public ssh key please")
@@ -184,7 +184,7 @@ If you need to invite multiple people to an event (hackathon, course, etc), the
* Does not work (yet?) with [`mosh`](https://mosh.org/)
* It is not possible for a user to access a host with the same name as the user. This is easily circumvented by changing the user name, especially since the most common use cases does not expose it.
* It is not possible access a host named `healthcheck` as this is a built in command.
* It is not possible to access a host named `healthcheck` as this is a built-in command.
---
@@ -215,7 +215,7 @@ cp sshportal.db sshportal.db.bkp
# run the new version
docker run -p 2222:2222 -d --name=sshportal -v "$(pwd):$(pwd)" -w "$(pwd)" moul/sshportal:v1.10.0
# check the logs for migration or cross-version incompabitility errors
# check the logs for migration or cross-version incompatibility errors
docker logs -f sshportal
```
@@ -276,7 +276,7 @@ cp sshportal.db sshportal.db.bkp
By default, the configuration user is `admin`, (can be changed using `--config-user=<value>` when starting the server. The shell is also accessible through `ssh [username]@portal.example.org`.
Each commands can be run directly by using this syntax: `ssh admin@portal.example.org <command> [args]`:
Each command can be run directly by using this syntax: `ssh admin@portal.example.org <command> [args]`:
```
ssh admin@portal.example.org host inspect toto
@@ -446,7 +446,7 @@ ssh localhost -p 2222 -l hostname
By default, `sshportal` uses a local [sqlite](https://www.sqlite.org/) database which isn't scalable by design.
You can run multiple instances of `sshportal` sharing a same [MySQL](https://www.mysql.com) database, using `sshportal --db-conn=user:pass@host/dbname?parseTime=true --db-driver=mysql`.
You can run multiple instances of `sshportal` sharing the same [MySQL](https://www.mysql.com) database, using `sshportal --db-conn=user:pass@host/dbname?parseTime=true --db-driver=mysql`.
![sshportal cluster with MySQL backend](https://raw.github.com/moul/sshportal/master/.assets/cluster-mysql.png)

View File

@@ -1,10 +1,11 @@
package bastion // import "moul.io/sshportal/pkg/bastion"
import (
"crypto/rand"
"fmt"
"io/ioutil"
"log"
"math/rand"
"math/big"
"os"
"os/user"
"strings"
@@ -617,7 +618,10 @@ func DBInit(db *gorm.DB) error {
}
if count == 0 {
// if no admin, create an account for the first connection
inviteToken := randStringBytes(16)
inviteToken, err := randStringBytes(16)
if err != nil {
return err
}
if os.Getenv("SSHPORTAL_DEFAULT_ADMIN_INVITE_TOKEN") != "" {
inviteToken = os.Getenv("SSHPORTAL_DEFAULT_ADMIN_INVITE_TOKEN")
}
@@ -673,12 +677,16 @@ func DBInit(db *gorm.DB) error {
}).Error
}
func randStringBytes(n int) string {
func randStringBytes(n int) (string, error) {
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
r, err := rand.Int(rand.Reader, big.NewInt(int64(len(letterBytes))))
if err != nil {
return "", fmt.Errorf("failed to generate random string: %s", err)
}
b[i] = letterBytes[r.Int64()]
}
return string(b)
return string(b), nil
}

View File

@@ -1640,11 +1640,15 @@ GLOBAL OPTIONS:
name = c.String("name")
}
r, err := randStringBytes(16)
if err != nil {
return err
}
user := dbmodels.User{
Name: name,
Email: email,
Comment: c.String("comment"),
InviteToken: randStringBytes(16),
InviteToken: r,
}
if _, err := govalidator.ValidateStruct(user); err != nil {