Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Used by the Computer Science House "csh_auth" library
# For more info, see https://github.com/liam-middlebrook/csh-auth
# https://wiki.csh.rit.edu/wiki/SSO
CSH_AUTH_CLIENT_ID=develop
CSH_AUTH_CLIENT_SECRET=
CSH_AUTH_STATE=2b3e8ca35c5bb772b63760012c270f25
CSH_AUTH_JWT_SECRET=3dde79fb4df2277cc9d84c93d3e0f69a
CSH_AUTH_SERVER_HOST=sso.csh.rit.edu
CSH_AUTH_REDIRECT_URI=http://localhost:8080/auth/redir

# S3 Bucket credentials. Ask an RTP for credentials or
# spin one up yourself using DEaDASS
# https://wiki.csh.rit.edu/wiki/S3
S3_ACCESS_ID=
S3_SECRET_KEY=
S3_BUCKET_NAME=
S3_HOST=s3.csh.rit.edu

# Postgres URI. Spin up your own for development,
# or make one on DEADASS (don't do this)
DB_URI=postgresql://plug:fancypantspassword@plug-postgres:5432/plug?sslmode=disable

# LDAP Creds. Consult the wiki page listed in the README.md
# https://wiki.csh.rit.edu/wiki/LDAP
LDAP_BIND_DN=uid=<username>,cn=users,cn=accounts,dc=csh,dc=rit,dc=edu
LDAP_BIND_PW=
LDAP_HOST=ldap.csh.rit.edu:636
LDAP_WRITE_MODE=false

# Gin-gonic settings. Base path should be set so it can find
# your resources.
GIN_MODE=release
BASE_PATH=./
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ FROM alpine:latest

COPY --from=builder /build/csh-plug .
COPY ./templates ./templates
COPY ./static ./static
ENTRYPOINT ["./csh-plug"]
3 changes: 0 additions & 3 deletions HACKING/README.md

This file was deleted.

7 changes: 0 additions & 7 deletions HACKING/dev_server.sh

This file was deleted.

7 changes: 0 additions & 7 deletions HACKING/launch_environment.sh

This file was deleted.

26 changes: 0 additions & 26 deletions HACKING/sample.env

This file was deleted.

79 changes: 78 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,78 @@
# csh-plug
CSH Plug
========

Plug is the advertisement platform of the future.

Development
-----------

## Running
It is likely easier to use containers like `podman` or `docker` or the corresponding compose file

With podman, I have been using

```sh
podman compose up --watch
```

If you want, you can run without auto rebuild using
```sh
podman compose up --force-recreate --build
```
Which can be restarted every time changes are made.

## Config
To easily configure your workspace, copy the `.env.example` into a new `.env` file.

### Add OIDC Config
Reach out to an RTP to get OIDC credentials that will allow you to develop locally behind OIDC auth

You can also fetch dev credentials from the wiki (https://wiki.csh.rit.edu/wiki/SSO).

The `CSH_AUTH_STATE` and `CSH_AUTH_CLIENT_SECRET` are each a unqiue sequence of 16+ random characters, I recommend using the openssl command line utilities `openssl rand -hex 16`

```bash
CSH_AUTH_CLIENT_ID=
CSH_AUTH_CLIENT_SECRET=
CSH_AUTH_STATE=
CSH_AUTH_JWT_SECRET=
CSH_AUTH_SERVER_HOST=sso.csh.rit.edu
CSH_AUTH_REDIRECT_URI=http://localhost:8080/auth/redir
```

### Add LDAP Config
Authenticate with LDAP using your CSH account credentials by following the instructions on the wiki (https://wiki.csh.rit.edu/wiki/LDAP).

Set the `LDAP_WRITE_MODE` environment variable to `false` to prevent attempted writes to LDAP, it will default to false if unset for safety.

```bash
LDAP_BIND_DN=uid=<username>,cn=users,cn=accounts,dc=csh,dc=rit,dc=edu
LDAP_BIND_PW=(Your CSH account password)
```

### Add S3 Config
An S3 bucket is used to store images that users upload. In order to have this work properly, you need to provide some credentials to the app.

There are 2 ways that you can get the needed credentials.
1. Reach out to an RTP for creds to the dev bucket
2. Create your own bucket using [DEaDASS](https://deadass.csh.rit.edu/), and the site will give you the credentials you need.

```bash
S3_ACCESS_ID=
S3_SECRET_KEY=
S3_BUCKET_NAME=
S3_HOST=s3.csh.rit.edu
```

### Database
You can either develop using the dev database, or use the local database provided in the docker compose file

Using the local database is detailed below, but both options will require the dev database password, so you will have to ask an RTP for this too

## Testing Locally

### Admin Dashboard Access
Modify the `CheckIfAdmin` function in `ldap.go` to always return true which will grant you admin access.

### Drink Credits
Modify the `DecrementCredits` function in `ldap.go` to give yourself credits if your account doesn't have them already.
2 changes: 1 addition & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (c DBConnection) pingDBAlive() {
}
}

func (c DBConnection) create_table_safe(name, sql string) {
func (c DBConnection) create_table_safe(name string, sql string) {
c.pingDBAlive()
rows, err := c.con.Query("SELECT 1::integer FROM pg_tables WHERE schemaname = 'public' AND tablename = $1::text;",
name)
Expand Down
41 changes: 41 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
services:
plug:
build: .
volumes:
- ./migrations:/opt/conditional/migrations
container_name: plug
depends_on:
plug-postgres:
condition: service_healthy
env_file:
- path: .env
required: false
environment:
- BASE_PATH=/
ports:
- "127.0.0.1:8080:8080"
develop:
watch:
- action: sync+restart
target: /templates
path: ./templates

plug-postgres:
image: docker.io/postgres:18
container_name: plug-postgres
environment:

@datadog-computersciencehouse datadog-computersciencehouse Bot Nov 6, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 High: Hardcoded credential in service environment

Storing credentials such as passwords, API keys, or tokens as literal values in the `environment` section exposes them in version control, container inspect output, and process listings. Any developer, CI system, or atta... (...read more)

Storing credentials such as passwords, API keys, or tokens as literal values in the environment section exposes them in version control, container inspect output, and process listings. Any developer, CI system, or attacker with read access to the Compose file or the running container can retrieve the credential. Sensitive values should be passed via Docker secrets (secrets:) or referenced as environment variable placeholders (e.g., DB_PASSWORD: ${DB_PASSWORD}) rather than hardcoded literals.

Helpful? 👍/👎 View in Datadog  Leave us feedback  Documentation
🚩 Report as false positive. Flags the rule for review to improve detection accuracy.

POSTGRES_PASSWORD: fancypantspassword
POSTGRES_USER: plug
POSTGRES_DATABASE: plug
ports:
- "127.0.0.1:5432:5432"
volumes:
- pgdata:/var/lib/postgresql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U plug"]
interval: 5s
timeout: 5s
retries: 5

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not gonna make you but you could add an s3 client :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean like a lightweight s3 emulator in another container? Is this related to your review comment?

btw you don't need to add s3 to local running, and if you do, you could also do anotehr pr if you want


volumes:
pgdata:
33 changes: 0 additions & 33 deletions env-template

This file was deleted.

23 changes: 16 additions & 7 deletions ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,34 @@ package main
import (
"crypto/tls"
"fmt"
"strconv"
"strings"

log "github.com/sirupsen/logrus"
"gopkg.in/ldap.v2"
"strconv"
)

type LDAPConnection struct {
app *PlugApplication
con *ldap.Conn
host string
bind_dn string
bind_pw string
app *PlugApplication
con *ldap.Conn
host string
bind_dn string
bind_pw string
writeMode bool
}

func (c *LDAPConnection) Init(
app *PlugApplication,
host,
bind_dn,
bind_pw string) {
bind_pw string,
write_mode string) {

c.app = app
c.host = host
c.bind_dn = bind_dn
c.bind_pw = bind_pw
c.writeMode = strings.ToLower(write_mode) == "true"

c.reconnectToLDAP()
}
Expand Down Expand Up @@ -129,6 +134,10 @@ func (c LDAPConnection) HasEnoughCredits(username string, credits int) bool {
}

func (c LDAPConnection) DecrementCredits(username string, credits int) bool {
if !c.writeMode {
return true
}

balance := c.CheckCredits(username)
newBalance := balance - credits

Expand Down
21 changes: 13 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ func (a *PlugApplication) Init(
s3_host,
s3_access_id,
s3_secret_key,
s3_bucket_name,
ldap_host,
ldap_bind_dn,
ldap_bind_pw,
ldap_write_mode,
base_path,
auth_client_id,
auth_client_secret,
Expand All @@ -48,10 +50,11 @@ func (a *PlugApplication) Init(
// S3 Connection
a.s3.Init(s3_host,
s3_access_id,
s3_secret_key)
s3_secret_key,
s3_bucket_name)

// LDAP connection
a.ldap.Init(a, ldap_host, ldap_bind_dn, ldap_bind_pw)
a.ldap.Init(a, ldap_host, ldap_bind_dn, ldap_bind_pw, ldap_write_mode)

a.base_path = base_path
a.router = a.createGinEngine()
Expand Down Expand Up @@ -91,16 +94,18 @@ func main() {
os.Getenv("S3_HOST"),
os.Getenv("S3_ACCESS_ID"),
os.Getenv("S3_SECRET_KEY"),
os.Getenv("S3_BUCKET_NAME"),
os.Getenv("LDAP_HOST"),
os.Getenv("LDAP_BIND_DN"),
os.Getenv("LDAP_BIND_PW"),
os.Getenv("LDAP_WRITE_MODE"),
os.Getenv("BASE_PATH"),
os.Getenv("csh_auth_client_id"),
os.Getenv("csh_auth_client_secret"),
os.Getenv("csh_auth_jwt_secret"),
os.Getenv("csh_auth_state"),
os.Getenv("csh_auth_server_host"),
os.Getenv("csh_auth_redirect_uri"),
os.Getenv("CSH_AUTH_CLIENT_ID"),
os.Getenv("CSH_AUTH_CLIENT_SECRET"),
os.Getenv("CSH_AUTH_JWT_SECRET"),
os.Getenv("CSH_AUTH_STATE"),
os.Getenv("CSH_AUTH_SERVER_HOST"),
os.Getenv("CSH_AUTH_REDIRECT_URI"),
"/auth/login",
)

Expand Down
Loading